Warning: preg_match(): Unknown modifier

Links for php scripts

Moderators: egami, macek, gesf

Post Reply
countrydj
New php-forum User
New php-forum User
Posts: 11
Joined: Wed Mar 30, 2011 7:17 am

Sun Nov 18, 2018 9:36 am

My script did work at one time, but it doesn't now.
This is the line that is throwing a wobbly:
if(preg_match("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $from)) {
I cannot see or find what is cousing the problem. This is the error message:
Warning: preg_match(): Unknown modifier '(' in /home/ukzone/in-uk.uk/html/calendar/register-exec.php on line 205
Can anybody help me with this problem?
Thanks,

John C

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 761
Joined: Mon Feb 22, 2016 5:52 pm

Sun Nov 18, 2018 12:30 pm

Are you sure

Code: Select all

if(preg_match("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $from)) {
is line 205?

countrydj
New php-forum User
New php-forum User
Posts: 11
Joined: Wed Mar 30, 2011 7:17 am

Sun Nov 18, 2018 12:45 pm

YES.
That is definately line 205.
It is a long script used for accepting input from the form. Then the script sends an email to ME ($from). that email is then returned with the validation.
This is when I get the error message.
I have to say though, that it wasn't always faulty. The script did work originally, but I cant remember whar I got the script from so I can't check it.

countrydj
New php-forum User
New php-forum User
Posts: 11
Joined: Wed Mar 30, 2011 7:17 am

Sun Nov 18, 2018 12:49 pm

I forgot to mention that if I replace the above code with:

Code: Select all

if(preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $from)) {
The script does work.

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 761
Joined: Mon Feb 22, 2016 5:52 pm

Mon Nov 19, 2018 1:37 pm

Syntactically, that line is correct.

If this is for checking an email address, you might want to change it to:

Code: Select all

filter_var($email, FILTER_VALIDATE_EMAIL)

Post Reply