我在输入字段中接受多个电子邮件地址。我想验证以下内容:电子邮件地址必须以空格分隔,电子邮件地址不应超过5,电子邮件地址不可用在数据库中 我怎么能通过使用jquery或javascript,ajax
来做到这一点答案 0 :(得分:0)
<script>
function checkEmails(email) {
email = email .replace(/\ /g, '');
var emails = email.split(","),
status = true,
badEmail = '';
$.each(emails, function(i,v) {
if (!validateEmail(v)) {
status = false,
badEmail = badEmail+v+' ';
}
});
if(status == true) {
//All emails are right
}
else {
//Some emails are wrong
// emails list are badEmail
}
}
function validateEmail(email) {
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}