[Regular] how do I write and determine whether the submitted user name does not contain the following special characters? Method
Requirement for submitted registration username $ uname:
1. the name must consist of English and Chinese characters, but the name cannot contain spaces.
2 cannot contain the following special characters in $ arr2
3. it can contain Chinese brackets (")".
',',','.','? ','/',' ~ ','! ',' ¥ ','...... ','?? ','. ', PHP_EOL, chr (10), chr (13), "\ t", chr (32),); **/$ arr2 = array ('~ ','! ',' @ ',' # ',' $ ',' % ',' ^ ',' & ',' * ',' _ ',' + ', '|', '-', '=', '\', '{', '}', '[', ']', ':', '; ',' "',' \ ',' <','> ',',','. ','? ','/',' ~ ','! ',' ¥ ','...... ','?? ','. ', PHP_EOL, chr (10), chr (13), // \ r \ n "\ t", chr (32),); foreach ($ arr2 as $ k) {// I used preg_match to make the results messy. Later, we used strpos (default7 # zbphp.com) if (strpos ($ uname, $ k )! = False) {$ tips = "The registration name cannot contain special characters such as spaces, dots, and commas! "; Return array (false, $ tips) ;}return array (true, 'OK ');}
Reply to discussion (solution)
If (strlen ($ s) = strlen (str_replace ($ arr2, '', $ s) {// does not contain special characters} else {// contains special characters}
If ($ s = str_replace ($ arr2, '', $ s) {// does not contain special characters} else {// contains special characters}