Any value that starts with a digit is validated as number
See original GitHub issueThe number validator validates any number that starts with a digit, e.g. 1a
is accepted. This seems to be a problem of the value to number conversion:
let parsed = parseFloat(value);
if (this.isType(parsed)) return parsed;
return NaN;
From https://www.ecma-international.org/ecma-262/6.0/index.html#sec-parsefloat-string:
parseFloat
may interpret only a leading portion of string as a Number value; it ignores any characters that cannot be interpreted as part of the notation of an decimal literal, and no indication is given that any such characters were ignored.
What about changing the code to this:
let parsed = parseFloat(value);
if (parsed == value) return parsed;
return NaN;
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:25 (11 by maintainers)
Top Results From Across the Web
How to use DATA VALIDATION to allow numbers only - Got It AI
Want to learn more about DATA VALIDATION to allow numbers only? This post will give you an overview of how to use the...
Read more >Decimal or numeric values in regular expression validation
To allow numbers with an optional decimal point followed by digits. ... In regular expressions . has a special meaning - match any...
Read more ><input type="number"> - HTML: HyperText Markup Language
A number input is considered valid when empty and when a single number is entered, but is otherwise invalid. If the required attribute...
Read more >Use Data Validation function to limit number of digits in Excel
Use Data Validation function to limit number of digits in Excel · 1. Select the cells you want to limit digits, click Data...
Read more >Example: Matching Numeric Ranges with a Regular Expression
In the 3-digit range in our example, numbers starting with 1 allow all 10 digits for ... (or no character at all) to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This bug should be threated with high severity. Such a basic check must not fail in a validation library.
Just to add another voice - I was very shocked to see a string (for example: ‘12’) pass the number check. I was also very confused as to why the string ‘12F’ would pass my check of:
var number = yup.number().required().positive().integer();
I honestly thought I had an error in my code and spent a while trying different things.