[Regular] how do I write and determine whether the submitted user name does not contain the following special characters? Method

Source: Internet
Author: User
[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}

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.