对邮箱串进行验证,邮箱是用","逗号分隔的.
var emails ="
[email protected],
[email protected]";
function validateMail(emails){
//var ary = new Array("111","22","33","111"); 数组的定义方法
var emailArray = new Array();
emailArray =emails.replace(",",",").split(","); //替换中文输入法下的逗号
var flag = true;
var s = emailArray.join(",")+",";
for(var i=0;i<emailArray.length;i++) {
if(s.replace(emailArray[i]+",","").indexOf(emailArray[i]+",")>-1) {
alert("邮箱重复:" + emailArray[i]+",请修改!");
flag= false;
break;
}
var email = emailArray[i];
// alert(email);
if(email.indexOf("@")==-1){
alert("邮箱:"+email+"中必须包含@");
flag= false;
break;
}
if(email.indexOf(".")==-1){
alert("邮箱:"+email+"必须包含 \".\"");
flag= false;
break;
}
if(!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(email)){
alert("邮箱:"+email+"格式错误!");
flag= false;
break;
}
}
return flag;
}