Stoke
asked on
alphabetic and numeric character check
I am looking for a regEx that checks a password for me. It has to confirm the password must contain at least one alphabetic character and must contain at least one numeric character.
Thank you for your time and help.
Thank you for your time and help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This will test if there is at least 1 alphabetic character or 1 numeric character. If you want to fix a minimum length just increase the value 2 before the comma to the minimum length you require. It also accepts most punctuation characters.
\A(?=[!-/:-@[-\x60{-\x7E\x 80a-zA-Z0- 9]*?[a-zA- Z])(?=[!-/ :-@[-\x60{ -\x7E\x80- _a-zA-Z0-9 ]*?[0-9])\ S{2,}\z
If you don't want to accept punctuation or want to modify which may be accepted you simply need to edit from the ! to the \x80 in each of the character classes [] before the *?
Regards
\A(?=[!-/:-@[-\x60{-\x7E\x
If you don't want to accept punctuation or want to modify which may be accepted you simply need to edit from the ! to the \x80 in each of the character classes [] before the *?
Regards
This solution doesn't use the hex values so it might be a bit clearer to my previous one.
\A(?=[!-/:-@\[-`{-~€a-zA-Z 0-9]*?[a-z A-Z])(?=[! -/:-@\[-`{ -~€-_a-zA- Z0-9]*?[0- 9])\S{2,}\ z
\A(?=[!-/:-@\[-`{-~€a-zA-Z
/\d/ && /[[:alpha:]]/
in Perl would define alphabetic according to the current locale
in Perl would define alphabetic according to the current locale
if($_ =~/[a-z]/ && $_ =~/\d+/)
{
# "correct format";
}
else
{
# "wrong format";
}