New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JQUERY Validation Plugin bug -- rule of min(value) does not respect the minimum value, if the value contains commas #188
Comments
A proper solution would use Globalize (https://github.com/jquery/globalize) to handle the number parsing. Requiring that as a dependency isn't really an option, so we need to find a way to support it when you need it. |
I submit a solution (in French) : This post was inspired by this article : http://rebuildall.umbraworks.net/2011/03/02/jQuery_validate_and_the_comma_decimal_separator I think that is a proper solution pending that this issue is fixed. |
Mr. Arxuis -- Thank you very much for the reply to my query. We did as you suggested and it seems to work. However, I would like to point out a small syntax issue with your code : $.validator.methods.range = function (value, element, param) { return this.optional(element) || (safeStringToFloat(value) >= param[0] && globalizedValue } There is a close parenthesis missing here -- the corrected line should be : $.validator.methods.range = function (value, element, param) { return this.optional(element) || (safeStringToFloat(value) >= param[0] && globalizedValue); } Once again, thanks for your input and help in this matter. |
Hi, Endeed, I didn't seen that there was many errors in the script (my personal copy was good, though) I hava just submit the good version of the script. Enjoy ;) |
I recently submitted a PR For this issue with is the same as #379. I agree with @jzaefferer, my solution doesn't seem that great now thinking about a better, internationalized number parsing function. |
I changed my mind on making Globalize a dependency, see #581. Individual work arounds don't scale. |
Hi all, i know its been a year ago this issue raised, but i manged with this trick: first you initiate the amount field with thousand seperator and decimal seperator. the you override the minimum validator method: jQuery.validator.addMethod("min", function(value, element) { hope it helps :) |
In case anyone hits this and needs a quick, U.S.-but-customizable fix, I already had numeral.js involved and using it to preformat values was a pinch: https://gist.github.com/joeRinehart/0e8af523fdfc567cc670ddca2eaff137 |
Reference: http://docs.jquery.com/Plugins/Validation/Methods/min#value
Validation Plugin Version 1.8.1
jQuery Core Version 1.5.1
To reproduce the bug:
On the Demo for the Validate a minimum of 13,
the "min" rule in place, validation fails
Any number with a comma fails validation when the
"min" rule is in place, the validate plugin incorrectly reports an error
1,300 (with the comma) -- the error goes away
Expected behavior:
The plugin should treat numbers with commas in the same
manner as numbers without commas.
The same issue was encountered using the "range" rule
Appreciate any reply to help on this issue
The text was updated successfully, but these errors were encountered: