0

Why does PHP return 0 for current code? I just want to validate users name and allow to pass all letter signs available (incl. all characters like śćę......). What I'm doing wrong?

$var = 'cz -ęsc';
var_dump(preg_match('/^[\pL -]{1,35}$/', $var)); // int(0)
Alex Shesterov
  • 26,085
  • 12
  • 82
  • 103

1 Answers1

0

You need to enable Unicode for your regex, by setting the u flag, i.e.:

$var = 'cz -ęsc';
var_dump(preg_match('/^[\pL -]{1,35}$/u', $var)); // int(1)

For details, see the u (PCRE_UTF8) section in the docs: http://php.net/manual/en/reference.pcre.pattern.modifiers.php

Alex Shesterov
  • 26,085
  • 12
  • 82
  • 103