php - Regex to check for single/double quotation marks and parenthesis? -
i need have make kind of filter doesn't allow user use following characters in password:
" ' ( )
right code got following:
if(preg_match('/"/', $password)) { echo "illegal character found.."; }
i'm extremely bad regex , kind of appreciated, i've been looking around answers can't seem find both checks single , double quotation marks..
try this:
preg_match('~[\'"\(\)]~', $password); // return true when of '"() in password.
the whole code should be:
$password = '...'; if (preg_match('~[\'"\(\)]~', $password)) { echo 'password contains bad character'; } else { echo 'ok'; }
Comments
Post a Comment