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.

Validating integers

See original GitHub issue

I’m having an issue validating integers. I’d like '15' to be valid, whereas '15,6' should be invalid. If I use { strict: false }, '15' is fine but '15,6' gets coerced to 15 and is thus valid, even though I’d like it to be invalid. If I use { strict: true } every string input is invalid.

Is there another way to achieve this? 🤔

Example: https://runkit.com/eahlberg/integer-validation

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
avin-kavishcommented, Mar 2, 2020

Or you could have a config property to indicate the decimal separator

0reactions
Akius1commented, Jun 24, 2021

.matches(/^(?<=\s|^)\d+(?=\s|$)/, “Only whole numbers!”)

Nice. But still failing for leading. How can I validate for leading zeros

Read more comments on GitHub >

github_iconTop Results From Across the Web

integer validator - FormValidation
The best validation library for JavaScript. No dependency. ... Validate an integer number. The validator accepts both positive and negative numbers.
Read more >
Validating int value - java - Stack Overflow
Note that your validator actually tries to do two things: convert the input to an integer and validate the integer value.
Read more >
int validator - Apache Struts
Field Validator that checks if the integer specified is within a certain range. Parameters. fieldName - The field name this validator is validating....
Read more >
Validate that value is integer - MATLAB mustBeInteger
Validate That Input Contains Only Integers. Validate that a calculation results in integer values. A = randi(9)/randi(9); mustBeInteger(A).
Read more >
Python Tip: Validating user input as number (Integer)
Whole numbers (numbers with no decimal place) are called integers. To use them. ... Python Tip: Validating user input as number (Integer).
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