[Regular] how do I write and determine whether the submitted user name does not contain the following special characters? At last, the request for this post was edited by default7 from 2014-05-2518: 39: 45 for the submitted registration username & nbsp; $ uname & nbsp;: 1 & nbsp; the name must be a mix of Chinese Characters & nbsp; English characters, but must not contain spaces 2 & nbsp; it cannot contain the following [regular]. how do I write and determine whether the submitted user name does not contain the following special characters? Method
This post was last edited by default7 at 18:39:45
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 (")".
Function checkReg ($ uname)
{
/**
// Write a short
$ Arr2 = array (
'~ ','! ',' @ ',' # ',' $ ',' % ',' ^ ',' & ',' * ',' _ ',' + ', '|', '-', '= ','\\',
'{', '}', '[', ']', ':', ';', '"', '\', '<', '> ',',','. ','? ','/',
''',''','【',']','~ ','! ',' ¥ ','...... ',' -- ','. ',
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, strpos (default7 # zbphp.com) was used)
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 ');
}
------ Solution --------------------
If ($ s = str_replace ($ arr2, '', $ s )){
// Does not contain special characters
} Else {
// Contains special characters
}