Php digit-mixed Regular Expression for letters and numbers-PHP source code

Source: Internet
Author: User
Ec (2); & nbsp; Code copy Code as follows $ str1-8732dsef83dfrese8732DEef83dfrESe; Have friends write like this & nbsp; copy the code var_dump (preg_match ([0-9] +-[a-zA-Z0-9] {32}, $ str); script ec (2); script

The Code is as follows:
$ Str = '1-8732dsef83dfrese8732DEef83dfrESe ';

// Some friends wrote this.

The Code is as follows:
Var_dump (preg_match ('/[0-9] +-[a-zA-Z0-9] {32}/', $ str ));


// Possible problems

The Code is as follows:
$ Str = 'www1-8732dsef83dfrese8fdsfds3dfrESe-wfds111cn.netee ';
$ Str = 'wwwfsdgwww. 111cn. netwww1-873dfsfds32DEef83dfrESe-weeee ';
// Both forms are considered to be matched.
// So you should change it
Var_dump (preg_match ('/^ [0-9] +-[a-zA-Z0-9] {32} $/', $ str ));

// The correct method is

The Code is as follows:
Var_dump (preg_match ('/^ [0-9] +-[a-zA-Z0-9] {32} $/', $ str ));

// Look at other regular expressions (Chinese characters, letters, and numbers)
/*
First Chinese character,
2-4 digits are letters,
5th Chinese characters,
6-14 digits are numbers,
The last character is a Chinese character.

*/

The Code is as follows:

[U4e00-u9fa5] {1} [a-za-z] {2, 4} [u4e00-u9fa5] {5} [0-9] {6, 14} [u4e00-u9fa5] {1}

^ [U4e00-u9fa5uf900-ufa2d] [a-za-z] {3} [u4e00-u9fa5uf900-ufa2d] d {9} [u4e00-u9fa5uf900-ufa2d] $

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.