Skip to content

stringLength

Validates that a string's length is within specified minimum and maximum bounds.

Options

OptionTypeDefaultDescription
minnumberundefinedMinimum number of characters
maxnumberundefinedMaximum number of characters
trimbooleanfalseTrim whitespace before measuring length
messagestringlocale defaultCustom error message

Playground

Valid values

ValueNotes
"hello"5 characters — within min=3, max=20
"abc"3 characters — equal to min

Invalid values

ValueReason
"ab"2 characters — below min=3
"averylongusernamethatexceeds"Exceeds max=20

Notes

  • Empty string ("") always returns valid: true (unless min is set and greater than 0).
  • Combine with notEmpty to explicitly require a non-empty value.

Released under the MIT License.