JavaScript Coder

Javascript password validation alphanumeric string

javascript form validation password validation alphanumeric validation

In case you want to allow only alpha-numeric characters in your password, here is the validation to check that condition:

Alpha-numeric regular expression test

Here is the function to test whether the inut matches an alphanumeric pattern:

function validateAlphaNumericPassword(pwd)
{
  var re = /^[a-z0-9]+$/i
  
  return re.test(pwd)
}

Alphanumeric with hyphen

Sometimes, you may want to allow some characters like hyphen ( - ) in addition to alpha-numeric characters. Here is the validation

function validatePassword(pwd)
{
  var re = /^[a-z0-9\-]+$/i
  
  return re.test(pwd)
}

If you notice, we just added the hyphen character to the list of allowed characters

See Also