Validating email address regular expression

Posted: 3 November 2010 in Uncategorized

The following example details in javascript how to validate an email address for the web using a regular expression.

            function validateEmailAddress(emailAddress){
                var emailRegex = /^(\w|\-|\_|\.|\'|\#|\$|\*|\/|\^|\!|\%|\&|\=|\||\~|\{|\})+\@((\w|\-|\_)+\.)+[a-zA-Z]{2,}$/;

            prompt("",validateEmailAddress("")); /* valid */
            prompt("email",validateEmailAddress("email")); /* according to the specification, this is valid for the local domain, but we don't have a local domain when we're on the interweb */

the same regular expression can be used to validate email addresses in perl or php


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s