How does the "regular" write that the user name submitted does not contain the following special characters? Method of seeking
This post was last edited by default7 on 2014-05-25 18:39:45
requirements for the submitted registered user name $uname:
1 The required name can be mixed in Chinese and English, but the middle cannot contain spaces
2 cannot contain special characters in the following $arr 2
3 but can contain the left and right brackets "(" ") in Chinese
function Checkreg ($uname)
{
/**
Write a short
$arr 2 = Array (
' ~ ', '! ', ' @ ', ' # ', ' $ ', '% ', ' ^ ', ' & ', ' * ', ' _ ', ' + ', ' | ', '-', ' = ', ' \ \ ',
' {', '} ', ' [', '] ', ': ', '; ', ' ' ', ' ' ', ' < ', ' > ', ', ', '. ', '? ', '/', ' ' ', ' ',
', ', ', ' ' ', ' ' ', ' ~ ', '! ', ' ¥ ', ' ... ', '--', ', ', ' ', ' ', '. ',
Php_eol, CHR, Chr (+), "\ T", Chr (32),
);
**/
$arr 2 = Array (
'~',
'!',
'@',
'#',
'$',
'%',
'^',
' & ',
'*',
'_',
'+',
'|',
'-',
'=',
'\\',
'{',
'}',
'[',
']',
':',
';',
'"',
'\'',
' < ',
' > ',
',',
'.',
'?',
'/',
'“',
'”',
'’',
'‘',
'【',
'】',
'~',
'! ',
' ¥ ',
'......',
'——',
'、',
'《',
'》',
'。 ',
Php_eol,
Chr (10),
CHR,//\r\n
"\ T",
Chr (32),
);
foreach ($arr 2 as $k) {
I used Preg_match results have garbled, all messed up. Later with Strpos (default7#zbphp.com)
if (Strpos ($uname, $k)!== false) {
$tips = "The registration name cannot contain special characters such as spaces, dots, commas, etc." ";
return Array (false, $tips);
}
}
Return Array (True, ' OK ');
}
------Solution--------------------
if ($s = = Str_replace ($arr 2, ", $s)) {
Does not contain special characters
}else{
Contains special characters
}