"Regular" How to write the user name that is submitted does not contain the following special characters? Method of seeking

Source: Internet
Author: User
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
}
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.