正则表达式判断号码靓号类型

靓号检测:主要可以检测连号(正连 12345、倒连65432)、AABB号、手机号码、日期号(生日号、年度号)、ABBCABB号,3位以上重复号。更多类型号码检测可以根据以下表达式改造。

  ' 匹配6位顺增
  regex.Pattern = "(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){5}\d"

  ' 匹配6位顺降
  regex.Pattern = "(?:9(?=8)|8(?=7)|7(?=6)|6(?=5)|5(?=4)|4(?=3)|3(?=2)|2(?=1)|1(?=0)){5}\d"

  ' 匹配6位顺增或顺降
  regex.Pattern = "(?:(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){5}|(?:9(?=8)|8(?=7)|7(?=6)|6(?=5)|5(?=4)|4(?=3)|3(?=2)|2(?=1)|1(?=0)){5})\d"

  匹配4-9位连续的数字
  (?:(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){3,}|(?:9(?=8)|8(?=7)|7(?=6)|6(?=5)|5(?=4)|4(?=3)|3(?=2)|2(?=1)|1(?=0)){3,})\d

  匹配3位以上的重复数字
  ([\d])\1{2,}

  匹配日期类型的数字
  (19|20)[\d]{2}(1[0-2]|0?[1-9])(31|2[0-9]|1[0-9]|0?[0-9])

  手机号码类
  (13[0-9]|15[0-9]|18[0-9])([\d]{2,4}){2}

  匹配33111类型的
  ([\d])\1{1,}([\d])\2{2,}

  匹配5331533类型的
  (([\d]){1,}([\d]){1,})\1{1,}

  匹配22334,123355类型的
  ([\d])\1{1,}([\d])\2{1,}

 

 

<?php
set_time_limit(0);

$count = 0;

for($i=210000; $i<1000000; $i++)
{
    $len = strlen($i)-2;
    $pattern1 = '/^(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){'.$len.'}\d/';
    @preg_match($pattern1,$i,$arr1);
    if (!empty($arr1[0]))
    {
        $count++;
        continue;
    }

    $pattern2 = '/(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){'.$len.'}\d$/';
    @preg_match($pattern2,$i,$arr2);
    if (!empty($arr2[0]))
    {
        $count++;
        continue;
    }

    $pattern4 = '/^(?:9(?=8)|8(?=7)|7(?=6)|6(?=5)|5(?=4)|4(?=3)|3(?=2)|2(?=1)|1(?=0)){'.$len.'}\d/';
    @preg_match($pattern4,$i,$arr4);
    if (!empty($arr4[0]))
    {

        $count++;
        continue;
    }


    $pattern5 = '/(?:9(?=8)|8(?=7)|7(?=6)|6(?=5)|5(?=4)|4(?=3)|3(?=2)|2(?=1)|1(?=0)){'.$len.'}\d$/';
    @preg_match($pattern5,$i,$arr5);
    
    if (!empty($arr5[0]))
    {
        $count++;
        continue;
    }
}
echo $count;

 

posted @ 2013-04-10 18:10  赵治鲁  阅读(1343)  评论(0编辑  收藏  举报