Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript check if string is number

// native returns true if the variable does NOT contain a valid number
isNaN(num)

// can be wrapped for making simple and readable
function isNumeric(num){
  return !isNaN(num)
}

isNumeric(123)         // true
isNumeric('123')       // true
isNumeric('1e10000')   // true (This translates to Infinity, which is a number)
isNumeric('foo')       // false
isNumeric('10px')      // false
Comment

if string has number javascript

str = "hello123!"
if(/d/.test(str))
  console.log(str+" has a number.")
Comment

if string has number javascript

const str = "vikash123!";

const hasNumber = /d/.test(str);
console.log(hasNumber) // true
Comment

js check if string is number

isNaN(num)         // returns true if the variable does NOT contain a valid number

isNaN(123)         // false
isNaN('123')       // false
isNaN('1e10000')   // false (This translates to Infinity, which is a number)
isNaN('foo')       // true
isNaN('10px')      // true
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to use session using javascript 
Javascript :: js get home url 
Javascript :: collision circle 
Javascript :: close exit app react native 
Javascript :: open link in new window chrome mac shortcut 
Javascript :: regex pattern for mobile number 
Javascript :: dangerouslySetInnerHTML did not match error in React 
Javascript :: javascript remove element by id 
Javascript :: js remove duplicates from array 
Javascript :: regex find lines containing two strings 
Javascript :: check class exist in element by parent id in jquery 
Javascript :: gitignore for angular 
Javascript :: free json hosting 
Javascript :: javascript sort array of objects by date 
Javascript :: how to run angular 
Javascript :: open json file r 
Javascript :: jacksepticeye 
Javascript :: random generating api for quotes 
Javascript :: node string to json 
Javascript :: get input value jquery 
Javascript :: Scrool to the bottom of a div 
Javascript :: string iterate in js 
Javascript :: dom key event shift is pressed 
Javascript :: checkbox click event jquery 
Javascript :: jquery on event snippet 
Javascript :: slice until character javascript 
Javascript :: jquery change text of div 
Javascript :: convert dict to json python 
Javascript :: window onload javascript 
Javascript :: javascript through array 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =