logo

Response

« Return to the main article

You are viewing this page out of context. To see it in the context it is intended please click here.

About This Page

Reply posted by R on Sat 16 Feb 2008 in response to Form Validator R3.0

Share a simple improvement

Add the below to the test procedure in order to validate basic email format
multi-value separated by comma. Does not handle phrases RFC-822 :)~ Enjoy


case "multiemail":
var emailStr = f.value.trim();
if(emailStr == ''){return true}; //the field is allowed to be empty


var mySplitResult = emailStr.split(",");
var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; //
valid
for(i = 0; i < mySplitResult.length; i++){
var testVal = mySplitResult[i].trim() +'';if ( !reg1.test( testVal ) &&
reg2.test( testVal ) ) { // this address passes
}
else {return false;}
}
return true;
break;