Number validation

This commit is contained in:
Angelos Chalaris
2017-12-07 02:25:29 +02:00
parent a9050ca220
commit accae7f71a
2 changed files with 18 additions and 0 deletions

View File

@ -26,6 +26,7 @@
* [Unique values of array](#unique-values-of-array)
* [URL parameters](#url-parameters)
* [UUID generator](#uuid-generator)
* [Validate number](#validate-number)
### Anagrams of string (with duplicates)
@ -209,6 +210,15 @@ var uuid = _ =>
)
```
### Validate number
Use `!isNaN` in combination with `parseFloat()` to check if the argument is a number.
Use `isFinite()` to check if the number is finite.
```js
var validateNumber = n => !isNaN(parseFloat(n)) && isFinite(n);
```
## Credits
*Icons made by [Smashicons](https://www.flaticon.com/authors/smashicons) from [www.flaticon.com](https://www.flaticon.com/) is licensed by [CC 3.0 BY](http://creativecommons.org/licenses/by/3.0/).*

View File

@ -0,0 +1,8 @@
### Validate number
Use `!isNaN` in combination with `parseFloat()` to check if the argument is a number.
Use `isFinite()` to check if the number is finite.
```js
var validateNumber = n => !isNaN(parseFloat(n)) && isFinite(n);
```