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.

main.js
// Before
const EMAIL_PATTERN = /* email regex */
const isValid = EMAIL_PATTERN.test('[email protected]')
main.js
// After
const { value, isValid } = validate.email('[email protected]')
// value: '[email protected]'
// isValid: true

Here’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.

main.js
validate.email(' [email protected] ')
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')