question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Any value that starts with a digit is validated as number

See original GitHub issue

The 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:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:25 (11 by maintainers)

github_iconTop GitHub Comments

44reactions
shoutcoolcommented, Dec 6, 2018

This bug should be threated with high severity. Such a basic check must not fail in a validation library.

13reactions
paintedbicyclecommented, Feb 26, 2018

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.

  • I did not expect a string to be allowed to be a number at all
  • and I was extremely confused on why a number that also has a letter in it would pass!
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found