Check If Preg Match False instead of True
I have this code that makes sure the username is only letters and numbers but then way my code is set up I need it to check if the preg_match is false. Right now it says "if secure echo this" I need it's logic to say "if not secure say this". Can someone help me out? if (preg_match('/[A-Z]+[a-z]+[0-9]+/', $username)) { echo 'Secure enough'; } You can negate the condition like this: if (!preg_match('/^[A-Za-z0-9]+$/', $username)) { echo 'Secure enough'; } Also, your regex needs to be [A-Za-z0-9]+ if you mean "alphanumeric" (only letters and numbers) as a whole. The regex in your code would