😎 Discover cool tips and tricks for customization in our next Developer Deep Dive virtual event - sign up now!

Email Field with Validation

By Saskia Bobinska

An Email field, that uses Regex-Validation.

email_field

{
  name: 'email',
  title: 'Email',
  type: 'string',
  validation: Rule => Rule.custom(email => {
      if (typeof email === 'undefined') {
          return true // Allow undefined values
      }
      
      return email.toLowerCase()
          .match(
              /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
            )
            
          ? true
          : 'This is not an email'
    })
}

Contributor

Other schemas by author