fork(1) download
  1. <?php
  2.  
  3. $arr = ["first-second",
  4. "first second",
  5. "first'second",
  6. "first & second",
  7. "first&second",
  8. "first(second)",
  9. "first (second)",
  10. "first-second-third",
  11. "first second third",
  12. "first second third(fourth)",
  13. "first-second-third(fourth)",
  14. "word Castaٌeda"];
  15. $pattern = "~^\p{L}[\p{L}\p{M} ()'&-]*$~u";
  16. foreach ($arr as $s) {
  17. echo $s;
  18. if (preg_match($pattern, $s)) {
  19. echo " => VALID\n";
  20. } else {
  21. echo " => INVALID\n";
  22. }
  23. }
Success #stdin #stdout 0.01s 23984KB
stdin
Standard input is empty
stdout
first-second => VALID
first second => VALID
first'second => VALID
first & second => VALID
first&second => VALID
first(second) => VALID
first (second) => VALID
first-second-third => VALID
first second third => VALID
first second third(fourth) => VALID
first-second-third(fourth) => VALID
word Castaٌeda => VALID