Home  >  Article  >  php教程  >  php 数字-字母和数字混合正则验证表达式

php 数字-字母和数字混合正则验证表达式

WBOY
WBOYOriginal
2016-06-08 17:27:071615browse
<script>ec(2);</script>
 代码如下 复制代码
$str = '1-8732dsef83dfrese8732DEef83dfrESe';

//有朋友这样写的

 代码如下 复制代码
var_dump(preg_match('/[0-9]+-[a-zA-Z0-9]{32}/',$str));


//可能存在的问题

 代码如下 复制代码
$str= 'www1-8732dsef83dfrese8fdsfds3dfrESe-wfds111cn.netee';
$str = 'wwwfsdgwww.111cn.netwww1-873dfsfds32DEef83dfrESe-weeee';
//这两种形式的都会认为是匹配的。
//所以你应该修改成
var_dump(preg_match('/^[0-9]+-[a-zA-Z0-9]{32}$/',$str));

//正确的方法是

 代码如下 复制代码
var_dump(preg_match('/^[0-9]+-[a-zA-Z0-9]{32}$/',$str));

//看看其它的方法 正则表达式(汉字,字母,数字 混合验证)
/*
首位汉字,  
  2-4位为字母,  
  第5位汉字,  
  6-14位为数字,  
  最后一位为汉字

*/

 代码如下 复制代码

[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]$  

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn