preg_match('/^[a-zA-Z0-9_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+$/', $username)
Look at the code above, who can explain. Better be more detailed. Thank you.
Reply content:
preg_match('/^[a-zA-Z0-9_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+$/', $username)
Look at the code above, who can explain. Better be more detailed. Thank you.
all characters in letters or numbers or under line or Han are required to be two or more.
/^[a-zA-Z0-9_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+$/
^
Match the start
$
Match end
[a-zA-Z0-9_]
Match a number, size, and letter, and write down the line.
[\x7f-\xff]
Match a code in the area of the character
Can actually be written as/^[a-zA-Z0-9_\x80-\xff]{2,}$/
{2,}
Represents two or more characters to match
Because the first place in the Han word is 1
, the whole word Fu Daisi 127
, is not included \x7f
, so can be \x7f
changed to \x80
(should).
P.S.: preg
Yes perl regular expression
, it's an acronym.
In addition, in order to make sure that the Chinese language must be matched, the correct match must be Chinese. It can also be a number of codes (such as odd numbers ...). ) What the.
So it's better to have /^(?:[a-zA-Z0-9_]|[\x80-\xff]{2})+$/
some insurance. As for the Japanese language, what is the language of the software?
And don't know why, JS to use [^\x00-\xff]
instead of [\x80-\xff]
, it may be to the multi-word character support of the difference bar.
Supplemental: A string in "js is a set of immutable ordered sequences of 16-bit values, each of which is usually derived from the Unicode character set. "So JS's regex can directly match the double-character.
Letters or numbers or underscores or characters of Chinese characters, need more than two