Javascript for validating email with regular expression

18 Jan

This will allow domain names with 2, 3 and 4 characters e.g.; us, tx, org, com, net, wxyz).

On the final line we call test method for our regular expression and pass the email address as input.

[email protected]– email’s first character can not start with dot “.” 7.

Validating email is a very important point while validating an HTML form.

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?

javascript for validating email with regular expression-62

Gmail, for example, lets you put a " " sign in the address to "fake" a different email (e.g.

It’s surprisingly easy, and you’re probably already doing it anyway. If you’re going to send an activation email to users, why bother using a gigantic regular expression?

Think about it this way: I register for your website under the email address . That’s probably going to bounce off of the illustrious mail daemon, but the formatting is fine; it’s a valid email address.

Here is the code to validate email address in Java Script using regular expression.

: Finally, the email address must end with two to four alphabets.