How can i check string has contains only letters numbers and spaces in any language?
I have tried bellow but it's not checks special characters like -*/.
preg_match("/[\p{L}]/u", $string )
preg_match("/[\p{N}]/u", $string )
You can use
preg_match('~^[\p{L}\p{N}\s]+$~uD', $string)
Details
^
- start of string [\\p{L}\\p{N}\\s]+
- one or more letters, digits or whitespaces $
- end of string. The u
modifier will enable Unicode string parsing and also make all patterns in the regex Unicode aware, and D
will make $
match the very end of the string.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.