Possible Duplicate:
Validate email address in Javascript?
Can anyone help me with email validation in javascript?.
Here's the script:
Function validateEmail(email)
{
var splitted = email.match("^(.+)@(.+)$");
if (splitted == null) return false;
if (splitted[1] != null)
{
var regexp_user = /^\"?[\w-_\.]*\"?$/;
if (splitted[1].match(regexp_user) == null) return false;
}
if (splitted[2] != null)
{
var regexp_domain = /^[\w-\.]*\.[A-Za-z]{2,4}$/;
if (splitted[2].match(regexp_domain) == null)
{
var regexp_ip = /^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
if (splitted[2].match(regexp_ip) == null) return false;
} // if
return true;
}
return false;
}
it runs fine but when someone enters "rohit@.com" as a email it takes that also rather it should be showing an error.
Can anyone help me on this to fix it? (Sorry I am a newbie to this so ignore any faults)