Method 1
The code is as follows: |
Copy code |
If (preg_match ("/^ d * $/", "4312 ")) { Echo "all numbers "; } If (preg_match ("/^ [a-z] * $/I", "fdsFDfd ")) { Echo "all letters "; } If (preg_match ("/^ [a-zd] * $/I", "fd4fd34 ")) { Echo "has numbers and letters "; } |
Chinese characters
The code is as follows: |
Copy code |
$ Username = $ _ REQUEST ['username']; If (! Preg_match ("/^ [a-z0-9xa1-xff] {} $/", $ username )) { Echo "34r345 "; Exit; } |
The above is relatively scattered. Below we will summarize several
The code is as follows: |
Copy code |
$ Input_tag = $ _ POST ['tag']; $ Input_tag = explode (',', $ input_tag ); $ Input_tag = array_unique ($ input_tag ); $ Input_tag = array_diff ($ input_tag, array (null )); $ Leng = ''; $ True = ''; $ Comma = ''; Foreach ($ input_tag as $ v ){ If (strlen ($ v)> 18 ){ $ Leng. = $ comma. $ v; $ Comma = ','; } $ True. = $ comma. $ v; $ Comma = ','; } $ True = str_replace (',', '', $ true ); If (! Preg_match ('/^ [x80-xff_a-zA-Z0-9] + $/', $ true )){ Echo "<script> alert ('special symbols are not allowed !!! '); </Script> "; Exit; } If (! Empty ($ leng )){ Echo "<script> alert ('one tag can only contain six Chinese characters !!! '); </Script> "; Exit; } |