View Single Post
Old 05-22-2007, 02:12 AM   #1 (permalink)
jamesbond
Junior Member
 
Join Date: May 2007
Location: India
Posts: 2
Default Email Validation but small doubt

hi friends..........

The email validation script is working well but inbetween without comma it accepts but i want without comma it wont accept the email address that mean (2 emal or 3,4....) can u please check the script as i given below...........


Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <script language="javascript"> function validateEmail(addr,man,db) { if (addr == '' && man) { if (db) alert('email address is mandatory'); return false; } if (addr == '') return true; var invalidChars = '\/\'\\ ";:?!()[]\{\}^|'; for (i=0; i<invalidChars.length; i++) { if (addr.indexOf(invalidChars.charAt(i),0) > -1) { if (db) alert('email address contains invalid characters'); return false; } } for (i=0; i<addr.length; i++) { if (addr.charCodeAt(i)>127) { if (db) alert("email address contains non ascii characters."); return false; } } var atPos = addr.indexOf('@',0); if (atPos == -1) { if (db) alert('email address must contain an @'); return false; } if (atPos == 0) { if (db) alert('email address must not start with @'); return false; } if (addr.indexOf('@', atPos + 1) > - 1) { if (db) alert('email address must contain only one @'); return false; } if (addr.indexOf('.', atPos) == -1) { if (db) alert('email address must contain a period in the domain name'); return false; } if (addr.indexOf('@.',0) != -1) { if (db) alert('period must not immediately follow @ in email address'); return false; } if (addr.indexOf('.@',0) != -1){ if (db) alert('period must not immediately precede @ in email address'); return false; } if (addr.indexOf('..',0) != -1) { if (db) alert('two periods must not be adjacent in email address'); return false; } var suffix = addr.substring(addr.lastIndexOf('.')+1); if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') { if (db) alert('invalid primary domain in email address'); return false; } return true; } </script> </head> <body> <form name="myform" > <input name="email" value="" size="25" maxlength="40" type="text"><br><input name="submitit" value="Validate Email" onClick="if (validateEmail(form.email.value,1,1)) {alert('email address accepted'); return false;}" type="submit"> </form> </body> </html>

can u please check it as soon as possible

thanks in advance
jamesbond
jamesbond is offline   Reply With Quote
Sponsored Links