FlyAbove Posted September 27, 2022 Share Posted September 27, 2022 I am trying to make the password contain one uppercase letter when registering but I am not sure how to do that in PHP. Am I writing the right regex for it? //password must contain a capital letter if (preg_match('/((?=.*[A-Z]))/', $pw)) { array_push($this->errorArray, Constants::$passwordContainCapital); return; } Quote Link to comment https://forums.phpfreaks.com/topic/315377-have-a-password-with-one-uppercase/ Share on other sites More sharing options...
requinix Posted September 27, 2022 Share Posted September 27, 2022 You made it more complicated than it needs to be: /[A-Z]/ Quote Link to comment https://forums.phpfreaks.com/topic/315377-have-a-password-with-one-uppercase/#findComment-1601116 Share on other sites More sharing options...
morocco-iceberg Posted October 2, 2022 Share Posted October 2, 2022 You can also use a regex tester to confirm that it will behave the way you're expecting :) Quote Link to comment https://forums.phpfreaks.com/topic/315377-have-a-password-with-one-uppercase/#findComment-1601258 Share on other sites More sharing options...
Solution FlyAbove Posted November 11, 2022 Author Solution Share Posted November 11, 2022 I was able to solve the issue with this. if (!preg_match('/[A-Z]/', $pw)) { array_push($this->errorArray, Constants::$passwordContainCapital); return; } Quote Link to comment https://forums.phpfreaks.com/topic/315377-have-a-password-with-one-uppercase/#findComment-1602425 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.