Edit this page

rules Object

Set of custom validation rules. Those rules will extend the built-in ones.

Defining custom rules

<form id="myform">
    <input name="username"/> <br />
    <input name="town" /> <br />

      rules: {
        customRule1: function(input){
          // all of the input must have a value
          return $.trim(input.val()) !== "";
        customRule2: function(input) {
          //only 'Tom' will be valid value for the username input
          if (input.is("[name=username]")) {
            return input.val() === "Tom";
          return true;
      messages: {
        customRule1: "All fields are required",
        customRule2: "Your UserName must be Tom"
Is this article helpful? Yes / No
Thank you for your feedback!

Give article feedback

Tell us how we can improve this article