By Ali Hammad Baig on 6:20 AM

Filed Under:

This is a javascript function which validates and email address.

function validateEmail(emailStr)
{
emailStr=trim(emailStr);
var at="@"
var dot="."
var lat=emailStr.indexOf(at)
var lstr=emailStr.length
var ldot=emailStr.indexOf(dot)

if (emailStr.indexOf(at)==-1){
return true
}

if (emailStr.indexOf(at)==-1 || emailStr.indexOf(at)==0 || emailStr.indexOf(at)==lstr){
return true
}

if (emailStr.indexOf(dot)==-1 || emailStr.indexOf(dot)==0 || emailStr.indexOf(dot)==lstr){
return true
}

if (emailStr.indexOf(at,(lat+1))!=-1){
return true
}

if (emailStr.substring(lat-1,lat)==dot || emailStr.substring(lat+1,lat+2)==dot){
return true
}

if (emailStr.indexOf(dot,(lat+2))==-1){
return true
}

if (emailStr.indexOf(" ")!=-1){
return true
}

return false
}

0 comments for this post

Post a Comment

Blog Widget by LinkWithin