10 examples of 'check string is number js' in JavaScript

Every line of 'check string is number js' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
13public isNumber(value: any) {
14 return typeof value === 'number' && isFinite(value);
15}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

1function containsNumber(str) {
2 return !!str.match(/\d/g);
3}
15function number(value) {
16 return typeof value === 'number' || value instanceof Number;
17}
17export function isNumber(number) {
18 return typeof number === 'number';
19}
11function isNumber(value) {
12 return (value instanceof Number) || (typeof value == 'number');
13}
93function isNumber( object ) {
94
95 return typeof object == 'number';
96}
41function isNumber(str) {
42 return /^[-]?\d+(\.\d*)$/.test(str);
43}
119function checkIsNumberArrayString(str) {
120 if (!str.match(/^\s*(((\s*(-|\+)?((\.\d+)|(\d+\.\d+)|(\d+)|(\d+(\.\d+)?e(-|\+)?(\d+)))\s*,){0,2}(\s*(-|\+)?((\.\d+)|(\d+\.\d+)|(\d+)|(\d+(\.\d+)?e(-|\+)?(\d+)))))|((\s*(-|\+)?((\.\d+)|(\d+\.\d+)|(\d+)|(\d+(\.\d+)?e(-|\+)?(\d+)))\s){0,2}(\s*(-|\+)?((\.\d+)|(\d+\.\d+)|(\d+)|(\d+(\.\d+)?e(-|\+)?(\d+))))))\s*$/g))
121 throw new Error(`Attribute must be a comma- or space-separated sequence of up to three numbers, for example "1 2.5 3". Yours was "${str}".`)
122}
25export function isNumber(value: unknown): value is number {
26 return typeof value === "number" || value instanceof Number;
27}
40export function isNumber(num) {
41 return typeof num === 'number' && !Number.isNaN(num);
42}

Related snippets