I'm trying to check user password with this regular exp:
$regex='/^(?=.*[A-Za-z0-9@])(?=.*\d)[a-zA-Z0-9@]{6,12}$/';
if(isset($_POST['password']) && strlen($_POST['password'])>=6 &&
strlen($_POST['password']<=12) && preg_match($regex, $_POST['password'])){
echo 'ok';
}else{echo 'invalid password';}
I'd like the password to be from 6 to 12 chars, at least one digit and at least one Uppercase.
It doesn't work if the password is something like 12Hello instead it works with Hello12 , someone could please help?
Thanks
ok
for both12Hello
andHello12
, unless you're doing something other than what or in addition to you've posted. Here's a working demo. By the way, please try formatting your code before posting. The code you posted is difficult to read, which leads to errors.