I need a little help I want to check if input matchs with the mask
Mask is this: 12.345.678/9012-34 (xx.xxx.xxx/xxxx-xx)
What I’ve tried till now is this
$string = '12.345.678/9012-34';
if(!preg_match('/^[0-9]{2}.[0-9]{3}.[0-9]{3}/[0-9]{4}-[0-9]{2}$/', $string)) {
echo 'Doesnt match the mask!';
}
It didn’t work out. Thanks for any help.
You need to escape the
/and.literals you want to match, as you’re using the former for the regex delimiter and the.has special meaning in a regex (generally to match all chars except\n).I also used
\dinstead of[0-9]as it’s less to read and comprehend and they mean the same thing.