...

View Full Version : Regular Expression



ali.irfan
05-22-2009, 01:27 PM
Hi
i am using the following regular expression for the validation of Email address
/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;

but the problem is that if user enters any white space character while entering email address then email is considered as valid how ever we know that an email address can not contain any white space character i have tried a lot but could not get a correct regular expression so plz help me...........

randomuser773
05-22-2009, 02:47 PM
Hi
i am using the following regular expression for the validation of Email address
/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;

but the problem is that if user enters any white space character while entering email address then email is considered as valid

.+ == One or more of anything. You've been more specific elsewhere, so do it here as well.

Philip M
05-22-2009, 03:36 PM
Try this instead:-


if (!(/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@(([\w\-]?)+\.)+([a-z]{2,4})$/i.test(emailAddress.value))) {
alert ("Invalid email adddress");
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum