rulesObject
Set of custom validation rules. Those rules will extend the built-in ones.
Default rules:
- required - The rule requires that the element has a value.
- pattern - The rule constrains the value to match a specific regular expression.
- max - The rule constrains the maximum numeric values that can be entered.
- min - The rule constrains the minimum numeric values that can be entered.
- step - When used in combination with the min and max attributes, constrains the granularity of the values that can be entered.
- url - The rule constrains the value to a valid URL format.
- email - The rule constrains the value to a valid email format.
- date - The rule constrains the value to a valid date format.
Example
<form class="myValidator"> <p><input type="number" name="age" min="0" max="100" step="5"></p> <p><input type="url" name="WebAddress" placeholder="http://example.com" ></p> <button id="validate" class="k-button k-primary" type="button">Validate</button> </form> <script> $('#validate').click(function(){ var validator = $(".myValidator").kendoValidator({ }).data("kendoValidator"); validator.validate(); }) </script> Example - defining custom rules
<form id="myform"> <input name="username"/> <br /> <input name="town" /> <br /> <button>Validate</button> </form> <script> $("#myform").kendoValidator({ 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" } }); </script> In this article