'PHP preg_match not working as Input pattern

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"]);



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Wiktor Stribiżew