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.

Seltjoek
  • 168
  • 3
  • 14
  • 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. – Niko Apr 23 '12 at 21:39

2 Answers2

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'])))
Tchoupi
  • 14,560
  • 5
  • 37
  • 71
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.

Martin.
  • 10,494
  • 3
  • 42
  • 68
jancha
  • 4,916
  • 1
  • 24
  • 39