I'm a complete novice when it comes to regex. Could someone help me convert the following expression to preg?
ereg('[a-zA-Z0-9]+[[:punct:]]+', $password)
An explanation to accompany any solution would be especially useful!!!!
I'm a complete novice when it comes to regex. Could someone help me convert the following expression to preg?
ereg('[a-zA-Z0-9]+[[:punct:]]+', $password)
An explanation to accompany any solution would be especially useful!!!!
preg_match('/[a-zA-Z0-9]+[[:punct:]]+/', $password)
You simply put a / at the beginning and a / at the end. Following the / at the end you can put some different options:
i - case insensitive
g - do a gloabl search
For more information in the beautiful world of regex in PHP, check out this:
To answer your real question, you'd need to structure your code like:
if ( preg_match( '/[a-z]+/', $password ) &&
preg_match( '/[A-Z]+/', $password ) &&
preg_match( '/[0-9]+/', $password ) &&
preg_match( '/[[:punct:]]+/', $password ) ) ...
If you wanted to ensure the presence of at least one lowercase letter, at least one uppercase letter, at least one digit, and at least one punctuation character in your password.
Other questions you should read: