21,893
社区成员
发帖
与我相关
我的任务
分享
var str="17788888234";
var reg=/1\d{2}(\d)\1{3}(?!\1)\d{4}/gi;
document.write(reg.test(str));
$a = array(
'13012345678',
'13211113333',
'13644444444',
'136a4444224',
'1321111333332131',
'dasd1321111333332131'
);
string(11) "13012345678"
int(1)
string(11) "13211113333"
int(1)
string(11) "13644444444"
int(0)
string(11) "136a4444224"
int(0)
string(16) "1321111333332131"
int(1)
string(20) "dasd1321111333332131"
int(1)
<?php
$ar = array(
'13012345678',
'13211113333',
'13644444444'
);
foreach($ar as $val)
{
if(preg_match('/^1[3,5,8,7]\d(?!(\d)\\1{7})\d{8}/', $val))
{
echo $val . ' is ok.';
}
else
{
echo $val . ' is fail.';
}
echo '<br/>';
}
13012345678 is ok.
13211113333 is ok.
13644444444 is fail.
$str='13855555555';
if(preg_match('/^1[3,5,8,7]\d(\d)\1{7}$/',$str,$m)){
echo '后面 8 位数字不能相同';
}else{
echo '通过';
}
$a = array(
'13012345678',
'13211113333',
'13644444444',
'136a4444224',
);
$p = '/(?=\d{11})(?=1[3587]\d(?!(\d)\1{7}))/';
foreach($a as $t)
var_dump($t, preg_match($p, $t));
string(11) "13012345678"
int(1)
string(11) "13211113333"
int(1)
string(11) "13644444444"
int(0)
string(11) "136a4444224"
int(0)