Form validators
Usage
@mantine/form
package exports several functions that can be used in validation rules object.
Validation functions are tiny in size and provide basic validation, if you have complex validation requirements, use other types of validation.
Optional error
Last argument of all validator functions below is optional. If error is not set, then fields with failed validation will only have invalid styles without error message:
isNotEmpty
isNotEmpty
checks that form value is not empty. Empty string, empty array, false
, null
and undefined
values are considered to be empty. Strings are trimmed before validation.
isEmail
isEmail
uses /^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/
regexp to determine whether form value is an email:
matches
matches
checks whether form value matches given regexp. If form value is not a string, validation will be failed.
isInRange
isInRange
checks whether form value is within given min
-max
range. If form value is not a number, validation will be failed.
hasLength
hasLength
check whether form value length is within given min
-max
range.
hasLength
will work correctly with strings, arrays and any other objects that have length
property.
Strings are trimmed before validation.