帝国模板之家为广大用户提供专业、一站式建站服务。

网站开发

网站开发栏目,介绍前端、后台、服务器、数据库、建站工具等实用网站开发教程。

当前位置:首页 > 教程 > 网站开发 > 正文

js判断是不是靓号的正则表达式

帝国模板之家 2020-09-30 网站开发 评论
最近在做一个QQ靓号的网站,需要验证QQ号靓号的类型 比如:ABCDEF ,ABC, ABCABC ,ABABAB ,AAAAA ,AAAA ,AAA 等类型。下面归纳了一些常用的验证规则,适用于(连号检测,手机号码,日期号,生日号)。
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*';
    }
}

以上就是常见的一些靓号验证规则,更多类型号码检测可以根据以下表达式改造。
这世上无忧无虑的人,反而相对寿命会长点。

已有 位小伙伴发表了看法

欢迎 发表评论

  • 匿名发表

关于

帝国cms模板

网页插件

帝国模板之家 | www.moyouyouw.cn

本站所有模板/文章除标明原创外,均来自网络转载,版权归原作者所有,如果有侵犯到您的权益,请联系站长删除,谢谢! 寻找帝国cms模板首选帝国模板之家,用心做站,上线至今广受好评,值得信赖!

  • 交流群1:帝国cms交流群1
  • 交流群2:帝国cms交流群2
在线QQ 给我留言