Skip to content
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

Number validation cross culture #1577

Closed
MrGrabazu opened this issue Sep 11, 2015 · 3 comments
Closed

Number validation cross culture #1577

MrGrabazu opened this issue Sep 11, 2015 · 3 comments

Comments

@MrGrabazu
Copy link

I don't think it's an issue, but I've faced some difficulties to post a form with a decimal field in it.
Because I'm french and my decimal separator is a comma, jQuery Validation stop the post because my decimal is not a valid number.
It's not true, it's a well formatted number according to my culture specifications.
I searched and all the solutions I have found are to install jquery globalize (with his dependencies, cdrl.js) in my project to solve this matter, and other solutions that I don't want to.
I think I've found a better way to solve it by replacing the RegExp in the jquery validation source for the number validation method from

^-?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$

to

^-?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:(\.|,)\d+)?$

which is almost the same.

It work fine for all this decimal number format :

149.99
149,99
1,149.99

So, would it not be simpler to replace the english culture oriented number validation RegExp by this global culture oriented one ??

@staabm
Copy link
Member

staabm commented Sep 12, 2015

Your regexp doesnt work because it allows numbers with several commas in it like 1,400,90.

You should define a custom method which only matches the number format you like to support or redefine the number method from outside. See e.g. http://stackoverflow.com/questions/17444985/jquery-validate-and-mask-for-decimal-and-thousands-separator

AFAIR we dont support this feature natively.

@staabm
Copy link
Member

staabm commented Sep 12, 2015

Duplicate of #188 - should integrate Globalize to solve this properly.

@staabm staabm closed this as completed Sep 12, 2015
@MrGrabazu
Copy link
Author

I think this one doesn't validate 1,149,99

^-?((?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d+)|(?:\d+|\d{1,3}(?:\s?\d{3})+)?(?:,\d+))?$

Include Globalize is not the good choice for an application that runs into one single language. It's an haevy client side library just to recognize comma instead of point on client side validation.. Just because the default regex present in the jquery validation library is not enough complete. There is not thousand ways to write a decimal number I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants