正则表达式判断号码靓号类型
战国墨竹于 2018-04-20 10:38:35 发布6962 收藏 14 分类专栏: php 正则 php同时被 2 个专栏收录 95 篇文章0 订阅 订阅专栏 正则 3 篇文章0 订阅 订阅专栏靓号检测:主要可以检测连号(正连 12345、倒连65432)、AABB号、手机号码、日期号(生日号、年度号)、ABBCABB号,3位以上重复号。
更多类型号码检测可以根据以下表达式改造。
1.匹配6位顺增 (?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){5}\d
2.匹配6位顺降 (?:9(?=8)|8(?=7)|7(?=6)|6(?=5)|5(?=4)|4(?=3)|3(?=2)|2(?=1)|1(?=0)){5}\d
3.匹配6位顺增或顺降 (?:(?: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.匹配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
5.匹配3位以上的重复数字 ([\d])\1{2,}
6.匹配日期类型的数字 (19|20)[\d]{2}(1[0-2]|0?[1-9])(31|2[0-9]|1[0-9]|0?[0-9])
7.手机号码类 (13[0-9]|15[0-9]|18[0-9])([\d]{2,4}){2}
8.匹配33111类型的 ([\d])\1{1,}([\d])\2{2,}
9.匹配5331533类型的 (([\d]){1,}([\d]){1,})\1{1,}
10,匹配22334,123355类型的 ([\d])\1{1,}([\d])\2{1,}
11.末位匹配$
//aabb,允许aaaa
(\d)\1(\d)\2$
//abab,允许aaaa
(\d)(\d)\1\2$
//aaab,允许aaaa
(\d)\1\1\d$
//同时允许
(?:(\d)\1(\d)\2|(\d)(\d)\3\4|(\d)\5\5\d)$
//以上如果不允许aaaa,第二个(\d)改为((?!\1)\d)
//如aabb,不允许aaaa
(\d)\1((?!\1)\d)\2$
- var reg = new RegExp("(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){5}\\d", "g");
- if (phone.match(reg) != null) {
- code +=',ABCDEF';
- }
- var reg = new RegExp("(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){2}\\d", "g");
- if (phone.match(reg) != null) {
- code += ',ABC';
- }
- var reg = new RegExp("^(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){2}\\d[\\d][\\d](?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){2}\\d", "g");
- if (phone.match(reg) != null) {
- var result = phone.match(reg).toString();
- if (result.substring(0, 3) == result.substring(5,8)) {
- code += ',ABC**ABC';
- }
- }
- var reg = new RegExp("[\\d](?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){2}\\d[\\d](?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){2}\\d$", "g");
- if (phone.match(reg) != null) {
- var result = phone.match(reg).toString();
- if (result.substring(1, 4) == result.substring(5, 8)) {
- code += ',*ABC*ABC';
- }
- }
- var reg = new RegExp("(\\d)((?!\\1)\\d)\\2[\\d]", "g");
- if (phone.match(reg) != null) {
- var result = phone.match(reg).toString();
- if (result.substring(0, 1) == result.substring(3, 4)) {
- code += ',ABBA';
- }
- }
- var reg = new RegExp("(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){2}\\d{4}", "g");
- if (phone.match(reg) != null) {
- var result = phone.match(reg).toString();
- if (result.substring(0, 3) == result.substring(3, 6)) {
- code += ',ABCABC';
- }
- }
- var reg = new RegExp("^(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){2}\\d{4}", "g");
- if (phone.match(reg) != null) {
- var result = phone.match(reg).toString();
- if (result.substring(0, 3) == result.substring(3, 6)) {
- code += ',ABCABC*';
- }
- }
- var reg = new RegExp("(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){2}\\d{3}", "g");
- if (phone.match(reg) != null) {
- var result = phone.match(reg).toString();
- if (result.substring(0, 2) == result.substring(3, 5)) {
- code += ',ABCAB';
- }
- }
- var reg = new RegExp("(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){3}\\d", "g");
- if (phone.match(reg) != null) {
- code += ',ABCD';
- }
- var reg = new RegExp("(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){3}\\d{5}", "g");
- if (phone.match(reg) != null) {
- var result = phone.match(reg).toString();
- if (result.substring(0, 4) == result.substring(4, 8)) {
- code += ',ABCDABCD';
- }
- }
- var reg = new RegExp("(\\d)((?!\\1)\\d)\\1\\2\\1\\2", "g");
- if (phone.match(reg) != null) {
- code += ',ABABAB';
- }
- var reg = new RegExp("^(\\d)((?!\\1)\\d)\\1\\2\\1\\2", "g");
- if (phone.match(reg) != null) {
- code += ',ABABAB*';
- }
- var reg = new RegExp("(\\d)((?!\\1)\\d)\\1\\2", "g");
- if (phone.match(reg) != null) {
- code += ',ABAB';
- }
- var reg = new RegExp("^(\\d)((?!\\1)\\d)[\\d][\\d](\\d)((?!\\1)\\d)[\\d][\\d]", "g");
- if (phone.match(reg) != null) {
- var result = phone.match(reg).toString();
- if (result.substring(0, 2) == result.substring(4, 6)) {
- code += ',AB**AB**';
- }
- }
- var reg = new RegExp("[\\d][\\d](\\d)((?!\\1)\\d)[\\d][\\d](\\d)((?!\\1)\\d)$", "g");
- if (phone.match(reg) != null) {
- var result = phone.match(reg).toString();
- if (result.substring(2, 4) == result.substring(6, 8)) {
- code += ',**AB**AB';
- }
- }
- var reg = new RegExp('([\\d])\\1{4,}', "g");
- if (phone.match(reg) != null) {
- code +=',AAAAA';
- }
- var reg = new RegExp('(.)\\1{3}', "g");
- if (phone.match(reg) != null) {
- code +=',AAAA';
- }
- var reg = new RegExp('(\\d)\\1\\1((?!\\1)\\d)', "g");
- if (phone.match(reg) != null) {
- code += ',AAAB';
- }
- var reg = new RegExp('(.)\\1{2}', "g");
- if (phone.match(reg) != null) {
- code +=',AAA';
- }
- var reg = new RegExp('(.)\\1{1}', "g");
- if (phone.match(reg) != null) {
- code +=',AA';
- }
- //AABBB
- var reg = new RegExp("(\\d)\1((?!\\1)\\d)\\2\\2", "g");
- if (phone.match(reg) != null) {
- code +=',AABBB';
- }
- //AABB
- var reg = new RegExp("(\\d)\\1((?!\\1)\\d)\\2", "g");
- if (phone.match(reg) != null) {
- code +=',AABB';
- }
- //AABCC
- var reg = new RegExp("(\\d)\\1((?!\\1)\\d)((?!\\1)\\d)\\3", "g");
- if (phone.match(reg) != null) {
- var result = phone.match(reg).toString();
- if (result.substring(2, 3) != result.substring(0, 1) && result.substring(2, 3) != result.substring(3, 4)) {
- code += ',AABCC';
- }
- }
- var reg = new RegExp("(\\d)\\1((?!\\1)\\d)\\2((?!\\1)\\d)\\3", "g");
- if (phone.match(reg) != null) {
- var result = phone.match(reg).toString();
- if (result.substring(2, 4) != result.substring(0, 2) && result.substring(2, 4) != result.substring(4, 6)) {
- code += ',AABBCC';
- }
- }
- var reg = new RegExp("^(\\d)\\1((?!\\1)\\d)\\2((?!\\1)\\d)\\3", "g");
- if (phone.match(reg) != null) {
- var result = phone.match(reg).toString();
- if (result.substring(2, 4) != result.substring(0, 2) && result.substring(2, 4) != result.substring(4, 6)) {
- code += ',AABBCC*';
- }
- }
匹配号码后4位为ABAB:
“^\d*(\d)(\d)\1\2$”
匹配号码后4位为AABB:
“^\d*(\d)\1(\d)\2$”
// ABBABB
"^(\\d)(\\d)\\2\\1\\2\\2$"
// 4位以上 位递增或者递减(7890也是递增)
"(?:(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)|9(?=0)){2,}|(?:0(?=9)|9(?=8)|8(?=7)|7(?=6)|6(?=5)|5(?=4)|4(?=3)|3(?=2)|2(?=1)|1(?=0)){2,})\\d"
- //匹配6位顺增
- string pattern = "(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){5}\\d";
- //匹配6位顺降
- pattern = "(?:9(?=8)|8(?=7)|7(?=6)|6(?=5)|5(?=4)|4(?=3)|3(?=2)|2(?=1)|1(?=0)){5}\\d";
- //匹配6位顺增或顺降
- 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位连续的数字
- pattern = "(?:(?: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位以上的重复数字
- pattern = "([\\d])\\1{2,}";
- //匹配手机号码类
- pattern = "(13[0-9]|15[0-9]|18[0-9])([\\d]{2,4}){2}";
- //匹配连同号如“112233”“222333”
- pattern = "([\\d])\1{1,}([\\d])\\2{2,}"; //这个测试没有通过,要重新编写
- //匹配2233类型
- pattern = "([\\d])\\1{1,}([\\d])\\2{1,}";
- // 手机号、生日号、跟公司业务相关的号码
- "^(0|13|15|18|168|400|800)[0-9]*$"
- "^\\d{2}(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])$"
- "^\\d*(1688|2688|2088|2008|5188|10010|10001|666|888|668|686|688|866|868|886|999)\\d*$"
- // 重复号码,镜子号码
- "^(<a>\\d)(\\d)(\\d)\\1\\2\\3$"
- "^(\\d)(\\d)(\\d)\\3\\2\\1$"
- // AABB
- "^\\d*(\\d)\\1(\\d)\\2\\d*$"
- // AAABBB
- "^\\d*(\\d)\\1\\1(\\d)\\2\\2\\d*$"
- // ABABAB
- "^(\\d)(\\d)\\1\\2\\1\\2\\1\\2$"
- // ABCABC
- "^(\\d)(\\d)(\\d)\\1\\2\\3$"
- // ABBABB
- "^(\\d)(\\d)\\2\\1\\2\\2$"
- // AABAAB
- "^(\\d)\\1(\\d)\\1\\1\\2$"
- // 4-8 位置重复
- "^\\d*(\\d)\\1{2,}\\d*$"
- // 4位以上 位递增或者递减(7890也是递增)
- "(?:(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)|9(?=0)){2,}|(?:0(?=9)|9(?=8)|8(?=7)|7(?=6)|6(?=5)|5(?=4)|4(?=3)|3(?=2)|2(?=1)|1(?=0)){2,})\\d"
- // 不能以 518 、918 结尾
- "^[0-9]*(518|918)$"
标签:号码,正则表达式,靓号,substring,phone,result,var,reg,match From: https://www.cnblogs.com/tomcat2022/p/17663564.html