I'm using a regex below to validate password to accept alphanumeric characters only. The regex works if I enter 2 characters one alpha and one number but if more than two characters my regex doesn't work. I want if possible the following results as shown in "Expected Behavior". Can anyone help me rewrite my regex?
JavaScript
function checkPasswordComplexity(pwd) { var regularExpression = /^[a-zA-Z][0-9]$/; var valid = regularExpression.test(pwd); return valid; } Current Behavior
Password:Valid a1:true aa1:false aa11:false Expected Behavior
Password:Valid aa:false (should have at least 1 number) 1111111:false (should have at least 1 letter) aa1:true aa11:true a1a1a1a1111:true