PHP numeric-alphanumeric and numeric regular validation expressions

Source: Internet
Author: User
Tags numeric
The code is as follows Copy Code
$str = ' 1-8732dsef83dfrese8732deef83dfrese ';

It's written by a friend.

The code is as follows Copy Code
Var_dump (Preg_match ('/[0-9]+-[a-za-z0-9]{32}/', $str));


Problems that may exist

The code is as follows Copy Code
$str = ' www1-8732dsef83dfrese8fdsfds3dfrese-wfds111cn.netee ';
$str = ' wwwfsdgwww.111cn.netwww1-873dfsfds32deef83dfrese-weeee ';
Both of these forms will be considered to be matched.
So you should change it into
Var_dump (Preg_match ('/^[0-9]+-[a-za-z0-9]{32}$/', $str));

The right way is

The code is as follows Copy Code
Var_dump (Preg_match ('/^[0-9]+-[a-za-z0-9]{32}$/', $str));

Look at other methods of regular expressions (Chinese characters, letters, digital hybrid validation)
/*
First Chinese characters,
2-4 digits for the letter,
The 5th Digit Chinese character,
6-14 digits for the number,
The last one is Chinese characters

*/

The code is as follows Copy Code

[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.