我尝试制作 Ajax 表单并尝试在那里进行电子邮件验证。我找到了这个解决方案 http://jsfiddle.net/EFfCa/
但无法在我的脚本中打开它:
<script>
$('#joinForm').ajaxForm(function() {
var testEmail = /^[A-Z0-9._%+-]+@([A-Z0-9-]+\.)+[A-Z]{2,4}$/i;
var name = $("input[name=name]")
var email = $("input[name=email]")
if(name.val()==''||email.val()=='') {
$(".notify").show();
$(".notify p").text('empty');
} else if(testEmail.test(email.value)) {
$(".notify").show();
$(".notify p").text('email is wrong');
} else {
$(".notify").show();
$(".notify p").text('good');
}
});
</script>
即使电子邮件错误,表单也始终通过验证。空字段验证效果很好...
最佳答案
如果电子邮件正确,下面的行 else if(testEmail.test(email.value))
将返回 true。
按照您的逻辑,这就是电子邮件错误的地方,这可能是问题所在吗?
关于javascript - 使用 jQuery 检查电子邮件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30918035/