question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to validate a string with maximum length?

See original GitHub issue

It’s an obvious problem but for some reason this isn’t in the manual. How to validate something is a string, with all it’s subtle needs, but has a maximum length?

Seems a really basic one. But I can’t see any example how it would work, I can’t do a 'string' && value.length < 255 cause that wouldn’t work. So how to do a validation which takes a primary type and adds optional extras to it?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
CalebLovellcommented, Dec 10, 2020

in case anyone else stumbles across this thread like I did, length is now size. 😃

1reaction
ianstormtaylorcommented, Jun 6, 2020

This is solved in the newest release with “refinements”, specifically the length refinement, used like:

import { string, length } from 'superstruct'

const ShortString = length(string(), 1, 9)

And length works with the array struct too.

Read more comments on GitHub >

github_iconTop Results From Across the Web

stringLength validator - FormValidation
The best validation library for JavaScript. ... Validate the length of a string ... max *, data-fv-string-length___max or maxlength, Number, The maximum ......
Read more >
How can I validate the string length using java spring validation?
I have this field declared in a model class: @Size(min = 2, max = 200, message = "{validation. name. size}") private String name;...
Read more >
What validation rule so I use to validate the length of a string?
I need to add a validation rule that restrict a string to be between 3 and 255 characters in length. This is a...
Read more >
Validating String Length In The Model In ASP.NET Using C#
The validator [StringLength(80)] on this string tells the system that the maximum length for the string is 80 characters. If a string input...
Read more >
Validating string length separately vs. handling database error ...
And as databases typically don't support regex-based constraints, this validation has to be done in the application anyway. Then, the length ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found