Check for valid numeric strings - Node.js String

Node.js examples for String:Parse

Description

Check for valid numeric strings

Demo Code


// check for valid numeric strings
function isNumeric(a_string) {
  var strValidChars = "0123456789";
  var strChar;// ww w  . j  ava  2 s  . c o m
  var blnResult = true;

  if (a_string.length == 0)
    return false;

  // test a_string consists of valid characters listed above
  for (i = 0; i < a_string.length && blnResult == true; i++) {
    strChar = a_string.charAt(i);
    if (strValidChars.indexOf(strChar) == -1) {
      blnResult = false;
    }
  }
  return blnResult;
}

Related Tutorials