Validating email address syntax

In addition to the basic requirement that all fields must be filled out, the email address field must be a properly formatted email address. If the user fails to provide a properly formatted email address, a field-specific error message will inform the user that the email address syntax is incorrect.

We'll be using the EmailSyntax function from the validate package found within the shared folder:

const EmailRegex = `(?i)^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})+$`

func EmailSyntax(email string) bool {
validationResult := false
r, err := regexp.Compile(EmailRegex)
if err != nil {
log.Fatal(err)
}
validationResult = r.MatchString(email)
return validationResult
}

Recall that because the validate package is strategically placed in the shared folder, the package is meant to be isomorphic (used across environments). The job of the EmailSyntax function is to determine if an input string is a valid email address or not. If the email address is valid, the function will return true or the function will return false if the input string isn't a valid email address.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.80.101