Regular expression for validating email in javascript

Often, email validation code for web applications checks only for the position of @ and period characters, also assuming the @ character will be in the front of period. Did you know you can use a Java Script Regular Expressions method to check email addresses?

Last month I wrote about regular expressions in Java, today I’ll show you how to use regular expression in Java Script to validate email address.

Though this solution may be simple, I'm sure this is one of those useful things that people will be Googling for and deserves its own entry on the site If only Google would be the first place to look :) Just look at the duplicates of this closed every some time.

Any support for use of regex checks for e-mails I am 100% against.

To validate email address on client side, we can use java script with regular expression.

Java script can check the regular expression pattern for valid email address.

Unless you are validating for a specific domain where the email naming policy is more structured.

BTW, please don't validate email addresses on the client-side.

However, from a security standpoint, client side JS wouldn't protect you from XSS, SQL injection, or other vulnerabilities.

IMHO, it's best to do some basic validation on the front end so that your users don't lose the data they entered (EX: check for empty fields, validate phone numbers or SSN).

I'm tired of being told my e-mail address of "foo [email protected]" is invalid.

Tags: , ,