How to implement a custom dynamic error message to your jQuery Validator method?
$.validator.addMethod("checkEmailAvailability",function(value,element){ var result; $.ajax({ type: "POST", async: false, url:"includes/ajax/check-availability.php", data:{email:value}, dataType:"json", success: function(response) { result=response.success; $.validator.messages.checkEmailAvailability=response.msg; } }); return result; });
In the above code the message for the validator method is set by using
$.validator.messages.checkEmailAvailability=response.msg;
where the response.msg is the message we receive from the server.
This is a good and simple JavaScript snippet for the jQuery Validator plugin on how to add a jquery.validator.addmethod custom error message.
If you find this useful leave us a comment.
I have read your blog and really like the content, keep up the posts as I will be back.