Skip to main content
added 2 characters in body; deleted 94 characters in body
Source Link
Gabriele Petrioli
  • 197k
  • 35
  • 275
  • 331

Use a regular expression to check for digits only

var str = '192834a0'; alert( /^\d$/.test(str) ); 

accomplish this can be converted to a function.

function onlyNumbersisAlphanumeric( str ) { return /^\d$^[0-9a-zA-Z]+$/.test(str); } 

Use a regular expression to check for digits only

var str = '192834a0'; alert( /^\d$/.test(str) ); 

this can be converted to a function

function onlyNumbers( str ) { return /^\d$/.test(str); } 

Use a regular expression to accomplish this.

function isAlphanumeric( str ) { return /^[0-9a-zA-Z]+$/.test(str); } 
Source Link
Gabriele Petrioli
  • 197k
  • 35
  • 275
  • 331

Use a regular expression to check for digits only

var str = '192834a0'; alert( /^\d$/.test(str) ); 

this can be converted to a function

function onlyNumbers( str ) { return /^\d$/.test(str); }