I'm making up fake email addresses and I just want to make sure they are in a valid email format so I'm trying to remove any character that is not in the set below:
$jusr['email'] = preg_replace('/[^a-zA-Z0-9.-_@]/g', '', $jusr['email']);
I haven't had any trouble on my windows machine, but on the linux dev server I get this error each time this code runs:
Warning: preg_replace() [function.preg-replace]: Unknown modifier 'g' in /var/www/vhosts/....
I think it's the regex string, but I can't pin it down. Little help? Thanks.
Clarification: I'm not trying to accommodate all valid email addresses (unnecessary for my purpose), I just need to figure out what's wrong with my preg_replace regex.
g
is not a valid modifier in PCRE (the regex implementation PHP uses) because it's simply not needed; preg_replace()
will perform global replacements by default. You'll find the modifier in true Perl regex as well as JavaScript regex, but not in PCRE.
Just drop the g
:
$jusr['email'] = preg_replace('/[^a-zA-Z0-9.-_@]/', '', $jusr['email']);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With