Check for valid alphanumeric strings - Node.js String

Node.js examples for String:Parse

Description

Check for valid alphanumeric strings

Demo Code


// check for valid alphanumeric strings
function isAlphaNumeric(a_string) {
  var strValidChars = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  var strChar;/*from  w  w w  .  j  a  v a 2  s  .  co  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