PHP regular match 5 to 10 digits without repetition

WBOY
Release: 2016-07-25 08:57:56
Original
1763 people have browsed it
用正则表达式匹配数字很方便,这里介绍下用正则来匹配无重复的5到10位数字的方法,供大家参考。

匹配有重复的5到10位数字,正则表达式可以这样写:\d{5,10}。

若要匹配无重复的5到10位数字,参考了下网上别人的方法,如下: ^(?!\d*?(\d)\d*?\1)\d{5,10}$ 下面举一个用在php中的匹配无重复数字的例子,如下:

<?php
/**
* 正则匹配无重复的5到10位数字
* edit by bbs.it-home.org
*/
$str = '123456789';
$search = '/^(?!\d*?(\d)\d*?\1)\d{5,10}$/';
$result = preg_match($search,$str);

echo '匹配无重复的5到10位数字<br />';
if($result>0) {
    echo '符合';
}else {
    echo '不符合';
}
?>
Copy after login


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!