Possible Duplicate:
Validate email address in Javascript?
I have javascript for email validation :
//function to check emails
function echeck(str) {
var at="@"
var dot="."
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)
if (str.indexOf(at)==-1){
return false;
}
if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
return false;
}
if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
return false; }
if (str.indexOf(at,(lat+1))!=-1){
return false; }
if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
return false; }
if (str.indexOf(dot,(lat+2))==-1){
return false; }
if (str.indexOf(" ")!=-1){
return false;
}
return true;
}
It working fine but not checking this one -> !!!!!!!!!@####.com
Kindly help me to check extra spl characters in email.
Regards,
The example you provided is not a valid email address at least because ####.com is not a valid domain name. What you really should do is use regular expression to check the email address.
The most simple version of the regex would be
and a much more complete one would be
and the official RFC2822 implementation would be
And you would actually check the email address like so:
Note that it’s not a good idea to just do validation in JS. You should always perform another validation in the server – to prevent somebody passing bad data into your script and you happily using it. Keep in mind that you can’t guarantee that the form will be submitted from your page.