我的电子邮件正则表达似乎不起作用,它不会触发,
即使用户只输入一个表单,表单上的验证也会通过。
这是我的代码:
var a = ["txtTitle", "txtSurname", "txtEmail", "txtPostCode"];
$.each(a, function (index, value) {
if (sMsg == "") {
if ($("#" + value).val().trim() == "") {
var sText = $('td:first', $($("#" + value)).parents('tr')).text();
sMsg = "Please enter a " + sText;
$("#" + value).focus();
}
}
});
if (sMsg == "") {
if ($("#txtPhone").val().trim() == "" && $("#txtMobile").val().trim() == "") {
sMsg = "Please enter a phone or mobile number";
$("#txtPhone").focus();
}
}
if (sMsg == "") {
var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!regex.test($("#txtEmail").val())) {
sMsg = "Please enter a valid email address";
}
}
break;
答案 0 :(得分:0)
我现在已经解决了这个问题,结果是在电子邮件字段上有一个主要验证来检查它是否包含一个值,我只是将其删除并且有效
修改了这一行:
var a = ["txtTitle", "txtSurname", "txtEmail", "txtPostCode"];
到
var a = ["txtTitle", "txtSurname","txtPostCode"];