我通过以下方式调用验证表单函数:
$(document).ready(function () {
$('#MainContent_btnRegisterClient').click(function (e) {
return validateForm('.registerClient', '#MainContent_lblRegStatus', '#MainContent_txtClientEmail', e);
});
});
调用我的validateForm然后验证电子邮件:
//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页面调用它吗?
由于