Skip to content Skip to sidebar Skip to footer

Several Custom Validate Rules In Jquery Validate Plugin

I am using Jquery Validate plugin to check the user input however, i found that the option is not sufficient and i decided to use custom rules Are there any website provide those r

Solution 1:

you can customized jQuery validate plugin like this.

jQuery("form#my-form").validate({
            rules: {
                //input field name "inputName"
                //implement your rules here
                inputName: {
                    minlength: 3
                }
            },
            messages: {
                inputName: {
                    required : 'Your customized message'
                }
            }
        });

Solution 2:

you can add custom rules by extending the jquery validator

   jQuery.validator.addMethod("customdate", function(value, element) { 
   return this.optional(element) || {your rules}
     }, "eg YYYY-MM-DD");

see in here

http://docs.jquery.com/Plugins/Validation/Validator/addMethod#namemethodmessage

For number only, you don't need to write your own rules.It already include the feature,try digits and number

  1  $("#form").validate({
        rules:{
            inputtype:{required:true,digits:true}

        },
        messages:{
            inputtype:{required:"Please provide Number",digits,"Number Only!"}

        }
    });

    2.  $("#form").validate({
        rules:{
            inputtype:{required:true,number:true}

        },
        messages:{
            inputtype:{required:"Please provide Number",number,"Number Only!"}

        }
    });

Post a Comment for "Several Custom Validate Rules In Jquery Validate Plugin"