Validate
validate parses and validates common form fields, like email addresses, phone numbers and credit cards.
Parse and validate common form fields
validate returns the parsed value and whether it’s valid at the same time, so you don’t have to write custom regexes or search for validation libraries.
// Beforeconst EMAIL_PATTERN = /* email regex */// After
// value: '[email protected]'// isValid: trueHere’s a list of values that validate can verify
validate can verify:
- Email addresses
- Phone numbers
- Dates of birth
- Card numbers, expiry dates and CVVs
- Postal codes
- And more
See the guide for the full list.
validate.phoneNumber('+65 9123 4567')validate.dob('1990-05-10')validate.creditCard('4111 1111 1111 1111')validate.cardExpiry('12/29')validate.cardCvv('123', 'visa')validate.postalCode(' sw1a 1aa ', 'GB')