Number validation
This commit is contained in:
8
snippets/validate-number.md
Normal file
8
snippets/validate-number.md
Normal 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);
|
||||
```
|
||||
Reference in New Issue
Block a user