preg_match error Unknown modifier '{' [duplicate]
Asked Answered
J

2

0

What's wrong with this?

if((preg_match('[a-zA-Z]{1,7}+',$_POST['naam'])) and (preg_match('[^\@\#\<\>\&\*\/]+[a-zA-Z0-9]+!',$_POST['password'])))

the first regex i want a string of 1-7 long containing only alphabetic letters.

The second regex i want a string containing letters and numbers with an ! at the end.

Jadajadd answered 23/4, 2012 at 21:36 Comment(1)
If the first string is supposed to be 1-7 chars long, {1,7}+ does not make sense - that would match 1-7 chars, but one or more times. So 8 chars would be fine as well etc.Weeks
P
7

You're missing a delimiter around your regular expressions:

if((preg_match('/[a-zA-Z]{1,7}+/',$_POST['naam'])) and (preg_match('/[^\@\#\<\>\&\*\/]+[a-zA-Z0-9]+!/',$_POST['password'])))
Perfunctory answered 23/4, 2012 at 21:38 Comment(2)
Docs: php.net/manual/en/regexp.reference.delimiters.phpConservancy
Thanks it worked. I though that the single quotation marks were the delimiters :DJadajadd
S
3

{1,7} - this means 1 to 7

{1,7}+ - this is awkward, as + denotes that preceding char should be at least once. usually used as [a-z]+ <-- requires a-z

{1,7}+ is wrong.

Stunner answered 23/4, 2012 at 21:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.