This is the customized javascript email validation , based upon your requirement,you can be able to customize the validation with simple code.
function ValEmailId(arg)
{
var email=arg;
var f=0;
if (! allValidChars(email)) {
f=1;
}
else if (email.indexOf(".") < 1) {
f=1;
}
else if (email.indexOf("_") < 1 && email.indexOf("_")!=-1) {
f=1;
}
else if (email.indexOf("-") < 1 && email.indexOf("-")!=-1) {
f=1;
}
else if (email.indexOf("@") < 1) {
f=1;
}
else if (email.indexOf(".@")>=0 || email.indexOf("_@")>=0 || email.indexOf("-@")>=0 || email.indexOf("@@")>=0 || email.indexOf("--")>=0 || email.indexOf("__")>=0 || email.indexOf("-_")>=0 || email.indexOf("_-")>=0) {
f=1;
}
else if(email.indexOf("@.")>=0 || email.indexOf("@_")>=0 || email.indexOf("@-")>=0)
{
f=1;
}
else if (email.lastIndexOf(".") <= email.indexOf("@")) {
f=1;
}
else if (email.indexOf("@") == email.length-1) {
f=1;
}
else if (email.indexOf("..") >=0) {
f=1;
}
else if (email.indexOf(".") == email.length-1) {
f=1;
}
if(f==1)
{
alert("Please Enter Valid Email");
document.forms[0].emailId.focus();
return false;
}
}
function allValidChars(email) {
var parsed = true;
var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
for (var i=0; i < email.length; i++) {
var letter = email.charAt(i).toLowerCase();
if (validchars.indexOf(letter) != -1)
continue;
parsed = false;
break;
}
return parsed;
}
No comments:
Post a Comment