So I have this input pattern in HTML:
<input name="firstnamereg" type="text" pattern="[/p{L}+/u ]+">
But When I use the preg_match it does not work:
$regexFirstANDLastname = "/[/p{L}+/u ]+/";
preg_match($regexFirstANDLastname, $_POST["firstnamereg"]);
Advertisement
Answer
You need to use
pattern="[p{L}s]+"
This pattern, in Chrome and Firefox, will be compiles as a new RegExp("^(?:[\p{L}\s]+)$", "u")
regex object. The u
flag is used by default, you do not need to pass the flag in a regex literal construct. The pattern
regex is always set with a string, not a regex literal.