Adding custom rule to JQuery Validate

Adding custom rule to JQuery Validate

Hello:

I am having trouble getting adding custom rules to JQuery form validation to work properly. I want to use the default rules to make input required, make sure it is a number, and to make sure the number is 15 or greater. That was working fine.

But, I am now trying to add a custom rule to it that will allow only numbers that are divisible by 5 into the field. And I am not having any luck getting it to work. I also would like to be able to have a custom message for each error.

Can someone show me how to do this?

Thanks!

<html>

<head>

<script src="./jquerytest/jquery-1.9.1.min.js"></script>
<script src="./jquerytest/jquery.validate.min.1.8.js"></script>

<script>

$(document).ready(function() {

    jQuery.validator.addMethod("contact-us", function(value, element) {
        return $('.my-textbox').length / 5
    }, "Number must be divisible by 5");

    $('#contact-us').validate({
        rules:{
            'my-textbox':{
                required: true,
                number: true,
                min: 15
            },

            'my-textbox':{
                divisible: true
            }
         },

        messages:{
            'my-textbox':{
                required: 'This field is required.',
                number: 'Numbers only in this field.',
                min: 'Order quantity is 15 or more.'
            },

            'my-textbox':{
                divisible: 'Number must be divisible by 5'
            }

        }
    });
});

</script>



</head>

<body>

<form id="contact-us">

...

<input type="text" name="my-textbox" />

...

</form>

</body>

</html>