docs: def validate_email():
      """
      Validate the field is a valid email address.
  
      :raises: ``ValidationError('email')``
      """
      user_regex = re.compile(
          r"(^[-!#$%&'*+/=?^`{}|~\w]+(\.[-!#$%&'*+/=?^`{}|~\w]+)*$"
          r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]'
          r'|\\[\001-\011\013\014\016-\177])*"$)', re.IGNORECASE | re.UNICODE)
  
      domain_regex = re.compile(
          r'(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+'
          r'(?:[A-Z]{2,6}|[A-Z0-9-]{2,})$'
          r'|^\[(25[0-5]|2[0-4]\d|[0-1]?\d?\d)'
          r'(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\]$', re.IGNORECASE | re.UNICODE)
  
      domain_whitelist = ('localhost',)
  
      def email_validator(field, data):
          if field.value is None:
              return
  
          value = str(field.value)
  
          if '@' not in value:
              raise ValidationError('email')
  
          user_part, domain_part = value.rsplit('@', 1)
  
          if not user_regex.match(user_part):
              raise ValidationError('email')
  
          if domain_part in domain_whitelist:
              return
  
          if not domain_regex.match(domain_part):
              raise ValidationError('email')
  
      return email_validator