Saturday, May 18, 2013

How to customize error messages for jQuery validation plugin

jQuery validation plugin is lightweight and easy to use, the validation rules and error messages are provided by default.
Thus, it's save our time to validate various form fields. eg, credit card, email, etc.
But sometimes, we still customization to it, one of the very common customization is error message.

The option to customize error messages is opened, we can always provide our own error messages.
Here shown a sample for custom error messages.
messages: {
    field: {
        email: "Invalid email format"

Complete source,

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  <script src=""></script>
  <script type="text/javascript" src=""></script>

  rules: {
    emailaddr: {
      required: true,
      email: true
  messages: {
    emailaddr: {
 email: "Invalid email format"
<form id="myform">
  <label for="emailaddr">Required, email: </label>
  <input class="left" id="emailaddr" name="emailaddr" />



1 comment:

  1. Thank you for the Great help, the JSF inputs were driving me crazy till I found this. I was really stack overflow due to my huge primefaces hate.



Related Posts Plugin for WordPress, Blogger...