0

我有一个 jquery 来验证我的电子邮件 ID,但在验证后它提交表单而不是阻止它。

我的代码是

$(document).ready(function(e) {
    $('#personaledits').click(function(e) {
        $('#persemail').each(function(e) {
            email_address = $(this);
            email_regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i;
            if(!email_regex.test(email_address.val())){  alert('Please enter valid email'); e3.preventDefault(); return e.preventDefault(); return false; } 
        });
    });
});
4

2 回答 2

1

试试这个:

$(document).ready(function () {  // event is not required here
    $('#personaledits').click(function (e) {
        $('#persemail').each(function () {
            email_address = $(this);
            email_regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i;
            if (!email_regex.test(email_address.val())) {
                alert('Please enter valid email');
                e.preventDefault();    // You need to prevent the click event here
                return false;
            }
        });
    });
});
于 2013-05-10T06:55:10.100 回答
0

试试这个

$('#persemail').each(function(e) {
  email_address = $(this);
  email_regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    return regex.test(email);
 });
于 2013-05-10T06:53:50.113 回答