Sunday, July 15, 2012

Javascript Trim and Multiple Email Validation

function trim(str) {

if (!str

typeof str != 'string')

return null;

return str.replace(/^[\s]+/, '').replace(/[\s]+$/, '').replace(/[\s]{2,}/, ' ');

}

function emails(oSrc, args) {

var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

var address = args.Value;

var eadrs = address.split(';');



for (i = 0; i < eadrs.length; i++) {

var adr=trim(eadrs[i]);

if (adr != "" && adr != null)

if (reg.test(adr) == false) {

args.IsValid=false;

}

}

}
 





ClientValidationFunction="emails" ControlToValidate="TextBox2">

No comments: