I'm currently validating a form with JavaScript in which the user has to type their id number . I already figure out how to validate if the value is numeric, but I'm struggling to find a way to validate if the given number is integer or not.
Asked
Active
Viewed 288 times
-2
-
1https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Objetos_globales/Number/isInteger – Rashomon Jan 28 '20 at 20:46
-
Thanks, I'll check it – José Cañizales Jan 28 '20 at 20:55
-
Does this answer your question? [How do I check that a number is float or integer?](https://stackoverflow.com/questions/3885817/how-do-i-check-that-a-number-is-float-or-integer) – Rashomon Jan 28 '20 at 20:57
-
2Does this answer your question? [How to detect if a given number is an integer?](https://stackoverflow.com/questions/1323314/how-to-detect-if-a-given-number-is-an-integer) – Maximillian Laumeister Jan 29 '20 at 00:55
1 Answers
1
Try this:
Number.isInteger(Number(input))

Grey Chanel
- 212
- 1
- 5
-
-
Note about integer range with `Number.MAX_SAFE_INTEGER`. Let's see more about [Grandes enteros en JavaScript](https://codesearchable.com/es/4134437/) – Grey Chanel Jan 28 '20 at 21:28