Wednesday, June 15, 2011

Validate Email - Javascript


<script  type="text/javascript"> 
//Function to validate Email 
function  IsValidEmail(email) {
//var exclude=/[^@\\-\\.\\w]|^[_@\\.\\-]|[\\._\\-]{2}|[@\\.]{2}|(@)[^@]*\\1/; 
var  exclude = /[^@\\-\\.\\w]|^[_@\\.\\]|[\\._\\-]{2}|[@\\.]{2}|(@)[^@]*\\1/;
var  checkend = /\\.[a-zA-Z]{2,3}$/;
if  ((email.search(exclude) != -1) || (email.search(checkend) == -1)) {
return  false ;
}
atPos = email.indexOf("@" , 0);
pPos1 = email.indexOf("." , 0);
periodPos = email.indexOf("." , atPos);
pos1 = pPos1;
pos2 = 0;
while  (pos2 > -1) {
pos2 = email.indexOf("." , pos1 + 1);
if  (pos2 == pos1 + 1) {
return  false ;
} else  {
pos1 = pos2;
}
}
if  (atPos == -1) {
return  false ;
}
if  (atPos == 0) {
return  false ;
}
if  (pPos1 == 0) {
return  false ;
}
if  (email.indexOf("@" , atPos + 1) > -1) {
return  false ;
}
if  (periodPos == -1) {
return  false ;
}
if  (atPos + 1 == periodPos) {
return  false ;
}
if  (periodPos + 3 > email.length) {
return  false ;
}
return  true ;
}
</script>

No comments:

Post a Comment