Regular php regular code verification string rules: Can be combined with pure numbers or letters, only "-" can be used, but cannot contain Chinese characters or other characters. the character string cannot start with "-". cannot end with '-' ------ solution -------------------- PHPcodepreg_match (^ [a-z0-9] + [a-z0-9-] * [a-z0-9] + $ I, $ string ); ---- evaluate the php regular code to verify the string
String rules: you can use pure numbers or letters to combine them. you can only use "-", but cannot use Chinese characters or other characters. the character string cannot start with "-". it cannot end with "-".
------ Solution --------------------
PHP code
Preg_match ('/^ [a-z0-9] + [a-z0-9-] * [a-z0-9] + $/I', $ string );
------ Solution --------------------
I just pick the wrong one,
The first floor cannot match a single character :)
The second floor is also, \ w also contains _, the landlord does not want
------ Solution --------------------
The regular expression on the first floor is slightly modified to accommodate one character:
PHP code
/^ [A-z0-9] + [a-z0-9-] * [a-z0-9] + | [a-z0-9] + $/I
------ Solution --------------------
$ Str = '\ w + [0-9a-zA-Z \-] + \ w $'
------ Solution --------------------
I am also coming to join in
PHP code
/^ [0-9a-z] [-0-9a-z] * [0-9a-z] $/I