Reputation: 412
I've been looking for a while to an answer to this question; I'm trying to get the digits setting on jquery validation working without any success. Below are my settings:
{
min: 0,
max: 99,
digits: true,
messages: {
min: 'The minimum value is 0',
max: 'The maximum value is 99',
digits: 'The value must be a number'
}
}
I'm assigning my rules dynamically (I realize my code above doesn't list the name of the field I'm validating) and I've verified that all of the other rules (min and max) are validating properly, but when I put alphanumeric characters in the text box the "min" validator fires instead of the digits validator. I'm using the input type of text not number so that should not be the issue. Thanks in advance for any help.
UPDATE:
Also just for anyone searching out there if you are having problems where "min" works but "max" does not you need to make sure that the variable you are assigning to "max" is a JavaScript Number. You can assign a string "0" to min and it will perform the conversion fine but passing a string "99" to max will cause the max validation to stop working. That was another issue I was dealing with for a long time since in this solution I don't know the min and max values at design time. I pull them from attributes in the DOM which come across as strings.
Upvotes: 1
Views: 5402
Reputation: 20757
I'm no expert but what if you put digits: true,
above min and max:
{
digits: true,
min: 0,
max: 99,
messages: {
min: 'The minimum value is 0',
max: 'The maximum value is 99',
digits: 'The value must be a number'
}
}
Upvotes: 3
Reputation: 1647
Add following code before validate
jQuery.validator.setDefaults({
debug: true,
success: "valid"
});
You should use <input type="text" />
only not <input type="number"/>
Upvotes: 0