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 pattern does not match decimals without a leading numeric value. #103

Open
erichiggins opened this issue Jan 29, 2013 · 0 comments
Open

Comments

@erichiggins
Copy link

The current number pattern used by Backbone.Validation is /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.
Here are some tests which prove that it does not work as expected.

> var pattern = /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/;
> "0.5".match(pattern);
["0.5"]

> ".5".match(pattern);
null

JavaScript treats these the same, however:

> Number("0.5");
0.5
> Number(".5");
.5

When binding to a View, such as a form, it's common for users to enter decimals without leading zeros. This current pattern does not sufficiently accomodate that, and puts the burden on developers to handle it.

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

Successfully merging a pull request may close this issue.

1 participant