I am trying to create a regex to filter only alphabets or numbers from English and Japanese languages. This is what I have tried,
preg_match('/[\p{L}\p{N}\p{Katakana}\p{Hiragana}\p{Han}]+/u', $value)
But I am not getting the desired result. What might I be doing wrong? this one also i tried
preg_match('/[\p{Cn}\p{N}]+/u', $value)
also, I need to prevent special characters
('/[(a-zA-Z 0-9\_\{\}\!\$\%\&\.\|\?\*\+\(\)\-\~)(\p{Cn})]/', $value))
this one wont work together
Try with this regex : it will match letters (upper and lower case), numbers and unicode characters from katakana
, hiragana
and han
subset
preg_match('/^[a-zA-Z0-9\p{Katakana}\p{Hiragana}\p{Han} $]+/u', $value)
Edit : added space
to the list of allowed chars and $
and ^
to match entiere string.
STORE-11 ぼ <>?>>^^ † ‡ dd NN
will return 0 (no match) ぼ abc 12
will return 1 (matched) demo of the regex with given examples : https://www.phpliveregex.com/p/oef
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.