JS正则手机靓号处理AB ABAB AABB
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JS正则手机靓号处理AB ABAB AABB相关的知识,希望对你有一定的参考价值。
靓号检测:主要可以检测连号(正连 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‘; } var reg = new RegExp("(\\d)\1((?!\\1)\\d)\\2\\2", "g"); if (phone.match(reg) != null) { code +=‘,AABBB‘; } var reg = new RegExp("(\\d)\\1((?!\\1)\\d)\\2", "g"); if (phone.match(reg) != null) { code +=‘,AABB‘; } 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*‘; } }
以上是关于JS正则手机靓号处理AB ABAB AABB的主要内容,如果未能解决你的问题,请参考以下文章