Email Validation Function

  • Share this:

Code introduction


This function is used to validate whether the input string conforms to the format of an email address. If it does not conform, a ValidationError exception is raised.


Technology Stack : wtforms, re (regular expressions)

Code Type : Validation function

Code Difficulty : Intermediate


                
                    
def validate_email(form, field):
    if field.data and not re.match(r"[^@]+@[^@]+\.[^@]+", field.data):
        raise ValidationError('Invalid email address.')