Developed for a password-reset program, this routine ensures that the user-entered password matches specific password criteria. In this example, the password had to be between 8 and 12 characters long and contain at least one upper case, one lower case, and one numeric character. The order of these didn’t matter, as long as there was one of each.
After doing some testing, I settled on the LIKE operator, which (unlike popular assumptions) isn’t just for database matches.
If (Text1 Like "*[A-Z]*") And _ (Text1 Like "*[a-z]*") And _ (Text1 Like "*[0-9]*") And _ (Len(Text1) > 7 And Len(Text1) < 13) Then MsgBox "Password has correct usage."Else MsgBox "Password must be between 8 and 12 characters, " & _ "with one upper case letter, a lower case letter, and one number."End If