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
- Javascript password validation using regular expression
- How to Use the Dreamweaver Form Validation Feature
- JavaScript Form Validation : quick and easy!
- JavaScript Form Validation Script: More features
- Simfatic Forms Validation: save your time coding
- JavaScript Form Validation - Confirm Password
- JavaScript Form Validation - Date
- JavaScript Form Validation - Phone Numbers
- Javascript code to validate email addresses
- Javascript validation simple example code