imports jquery.min.js
imports jquery.validate.min.js
[Ajax]
[Form Validation]
--Add Validation Function
--Validation
imports jquery.validate.min.js
[Ajax]
function callAjax(){
$.ajax({type: "POST",
url: "ajax.asp",
data: {fun: "checkCardNO", CardNo: $("#CardNo").val()},
dataType:"html",
success:function(msg){
$("#AjaxValue").val(msg); /* Use Hidden input or div to transfer Ajax Value */
}
})
}
[Form Validation]
--Add Validation Function
$.validator.addMethod("checkRegisterd",
function(value, element) {
callAjax();
if($("#AjaxValue").val()=="Unregisted") return true;
} );
$.validator.addMethod("Useless",
function(value, element) {
callAjax();
if($("#AjaxValue").val()!="noData") return true;
} );
--Validation
$().ready(function() {
$("#form1").validate({
rules: { CardNo:
{ required: true,
Useless: true,
checkRegisterd: true
},
Name: "required",
Tel: {
required: true,
minlength: 10
},
Email: {
required: true,
email: true
}
},
messages: {
CardNo: {
required: "卡號必填",
Useless: "無效卡號",
checkRegisterd:"已註冊過"
},
Name: "姓名必填",
Tel: {
required: "請填寫正確手機號碼",
minlength: "請填寫正確手機號碼"
},
Email: "請填寫正確Email"
}
});
});
留言