minLength
Specifies the minimum length of a string.Syntax
The value must be a non-negative integer.Validation Rules
A string instance is valid if its length is greater than or equal to the specified value. The length is defined as the number of Unicode code points in the string.Examples
Default Behavior
OmittingminLength is equivalent to minLength: 0, which means empty strings are allowed.
maxLength
Specifies the maximum length of a string.Syntax
The value must be a non-negative integer.Validation Rules
A string instance is valid if its length is less than or equal to the specified value. The length is defined as the number of Unicode code points in the string.Examples
pattern
Validates that a string matches a regular expression.Syntax
The value must be a string containing a valid regular expression.Validation Rules
A string instance is valid if the regular expression matches the string successfully. Important: Regular expressions are not implicitly anchored. To match the entire string, use anchors like^ (start) and $ (end).
Regular Expression Dialect
The pattern should be a valid regular expression according to ECMA-262. See the interoperability considerations in the specification for details.Examples
Email Pattern
Phone Number Pattern
Alphanumeric Pattern
Partial Matching
Combining String Keywords
Multiple string validation keywords can be used together.Username Validation
- Is between 3 and 20 characters long
- Contains only letters, numbers, underscores, and hyphens
Password Validation
- Is at least 8 characters long
- Contains at least one lowercase letter, one uppercase letter, one digit, and one special character
Product Code
Unicode Considerations
TheminLength and maxLength keywords count Unicode code points, not bytes or visible characters.
"😀👍✨" has a length of 3 code points and is valid, even though it may appear as multiple characters depending on how emojis are rendered.