email validation with regular expressions using jquery

Pranay
Jan 19, 2015  ·  2347 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
}
AUTHOR

Pranay

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


Post a comment




Thank you! You are now subscribed.

Sign up for our newsletter

Subscribe to receive updates on our latest posts.

Thank you! You are now subscribed.