0

我通过以下方式调用验证表单函数:

$(document).ready(function () {

    $('#MainContent_btnRegisterClient').click(function (e) {
        return validateForm('.registerClient', '#MainContent_lblRegStatus', '#MainContent_txtClientEmail', e); 
   });
});

它调用我的 validateForm 然后 validateEmail:

//globals
var errAllfields = "Please complete all highlighted fields";
var errEmail = "Please enter a valid email address";

//email validator
function validateEmail(sEmail, message) {
var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
if (filter.test($(sEmail).val())) {
    return true;
}
else {
    $(message).text(errEmail);
    $(message).fadeIn();
    $(sEmail).css({
        "border": "1px solid #036447",
        "background": "#B5E0D2"
    });
    return false;
}
}
//textbox validation
function validateForm(className, message, email, e) {
var isValid = true;
//empty validation
$(className).each(function () {
    if ($.trim($(this).val()) == '') {
        isValid = false;
        $(message).text(errAllfields);
        $(message).fadeIn();
        $(this).css({
            "border": "1px solid #036447",
            "background": "#B5E0D2"
        });
    }
    else {
        $(this).css({
            "border": "",
            "background": ""
        });
    }
    //prevent form submission
    if (isValid == false)
        e.preventDefault();
});
//if all fields complete
if (isValid == true) {
    //if email field entered then validate
    if (email != null) {
        if (!validateEmail(email, message)) {
            return false;
        }

    }
}
}

但是,我想添加另一个功能(密码和密码确认比较功能)在这些功能成功后运行。实现这一目标的最佳方法是什么?我可以直接从我的 aspx 页面调用它吗?

谢谢

4

0 回答 0