I have 2 custom validation methods in my JSP which one of them has regex on the ID format entered, and the other method which help me to search whether the user has existed in the database.
Would like to ask how do I call my 2 custom validation methods inside my jquery validation plugin method (as seen below) before the form is submitted? Currently the validation only checks if the fields are empty. I would like to also check against the pattern of string entered (validateIDNo()) and if the user exists (checkUser(id)) before submitting the form.
Thank you so much.
function validateIDNo(){
//regex goes here, returns true/false
}
function checkUser(id){
//search database for ID, returns true/false
}
<script type="text/javascript">
//jquery validation Script
var _global_validator = null;
$(document).ready(
function() {
$("#form1").validate( {
errorElement : "small",
//ignore:".ignore",
invalidHandler : function(e, validator) {
_global_validator = validator;
renderCheckableUIValidation(validator)
},
errorPlacement : function(error, element) {
error.insertAfter(element);
},
messages : {
idNo: "Please enter your ID number",
mobileNo: "Please enter your mobile number",
emailAdd: "Please enter your email address"
},
submitHandler: function(form) {
form.submit();
}
}); //end validate
});
</script>