blanius
04-22-2003, 11:50 PM
Someone ask me if we could validate an email before submiting to the server script on an 3dfa form.... So here we go
errormsg=""//clear the error message if there is one
dot=email.indexOf(".",0)//find the dot
if (dot<1){//No dot?
errormsg+="No dot\n"
}
else{//there is a dot but must have at least two chars after it
ext=email.substr(dot+1)
if (ext.length<2 || ext.length>3){
errormsg+="Invalid Domain\n"
}
}
theat=email.indexOf("@",0)//find the at
if (theat<0){//no at?
errormsg+="No @ \n"
}
else{//found at but is there at least one character in front of it?
name=email.substr(0,theat)
if (name.length<1){
errormsg+="must have name\n"
}
}
trace (errormsg)
Example (http://bretlanius.com/flash/emailvalidate.html)
Source file (http://deadyeti.com/files/files.php?func=fileinfo&id=56)
errormsg=""//clear the error message if there is one
dot=email.indexOf(".",0)//find the dot
if (dot<1){//No dot?
errormsg+="No dot\n"
}
else{//there is a dot but must have at least two chars after it
ext=email.substr(dot+1)
if (ext.length<2 || ext.length>3){
errormsg+="Invalid Domain\n"
}
}
theat=email.indexOf("@",0)//find the at
if (theat<0){//no at?
errormsg+="No @ \n"
}
else{//found at but is there at least one character in front of it?
name=email.substr(0,theat)
if (name.length<1){
errormsg+="must have name\n"
}
}
trace (errormsg)
Example (http://bretlanius.com/flash/emailvalidate.html)
Source file (http://deadyeti.com/files/files.php?func=fileinfo&id=56)