rcleon
asked on
RegEx requiring one uppercase letter and at least one number
I have a RegEx that make sure that only alpha a-z or number 0-9 are accepted, it works but now my client wants to make sure that the password includes at least one uppercase letter some where and one number.
awawawaw or 12345678 will no longer be accepted it has to be something line awaw1awA.
It doesnt matter where the uppercase or number is I the password as long as one of each is provided.
I purchased RegexBuddy and it tell me that this is the correct syntax but it dose not work.
This is how I used it.
\A(?=\S*?[A-Z])(?=\S*?[a-z ])(?=\S*?[ 0-9])\S{6, }\z
if( preg_match('\A(?=\S*?[A-Z] )(?=\S*?[a -z])(?=\S* ?[0-9])\S{ 6,}\z,$_P OST['Passw ord']) )
Can anyone help? Or dose anyone has a better way to check that the password has the nessesary chars the password length is 8-12
awawawaw or 12345678 will no longer be accepted it has to be something line awaw1awA.
It doesnt matter where the uppercase or number is I the password as long as one of each is provided.
I purchased RegexBuddy and it tell me that this is the correct syntax but it dose not work.
This is how I used it.
\A(?=\S*?[A-Z])(?=\S*?[a-z
if( preg_match('\A(?=\S*?[A-Z]
Can anyone help? Or dose anyone has a better way to check that the password has the nessesary chars the password length is 8-12
I am afraid it is not possible with RE, because there is infinite possibilities how to count matching upper case letters, therefore it is not possible to construct finite automata on this. I suppose it is CF grammar ;-)
That requires an upper case letter, a lower case letter, a digit, and 6 or more non-space characters. so "awaw1awA" qualifies
I suggest you use separate regexps for testing that:
$has_uppercase = preg_match('/[A-Z]/',$pass );
$has_digit = preg_match('/[1-9]/',$pass );
$has_uppercase = preg_match('/[A-Z]/',$pass
$has_digit = preg_match('/[1-9]/',$pass
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you all!!!!