正则表达式学习:案例1--正则匹配13开头的移动手机号码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
    </style>
</head>
<body>

<script>

   /* */
    var str="13233334444 13566669999 13855556666";
    //移动号码第三位是4-9,联通号码第三位是0-3
    var reg1 = /13[4-9][0-9]{8}/g;
    var reg2 = /13[0-3][0-9]{8}/g;


    document.write("<li>"+"移动的手机号码为:"+str.match(reg1)+"</li>");
    document.write("<li>"+"联通的手机号码为:"+str.match(reg2)+"</li>");

   //compile()方法能加快执行速度
    reg1.compile(reg2);
    document.write("<li>"+"联通的手机号码为:"+str.match(reg1)+"</li>");



</script>

</body>
</html>

猜你喜欢

转载自blog.csdn.net/qq_32584661/article/details/80761502