email validation with regular expressions using jquery

- Pranay on Jan 19 '15
- 873 views

For email address validation there is Official Standard: RFC 5322 but the regex to match this standard is very complex and would not be suitable for implementation in our applications, but the below regex is the most appropriate to be used in our applications. I didn’t find a bug till now.

Regex:

[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:    
[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"

Sample Javascript to validate the format of email address:

var regex = [a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*
@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?;
if(regex.test(email)){
//valid email
}

About the author

Pranay Deegoju
Sitecore Certified Professional

A Software Engineer by profession, a part time blogger and an enthusiast programmer. You can find more about me here.



Leave your comments on this post here