码迷,mamicode.com
首页 > Web开发 > 详细

JS-regExp-正则表达式匹配2-6的数字

时间:2018-11-11 21:04:22      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:document   输入   图片   inpu   test   lan   prompt   charset   utf-8   

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <title>Document</title>
 </head>
 <body>
  <script>
        function testReg(){
            var regExp = /^\d{2,6}$/g;
            var input = prompt("请输入2-6位的数字:");
            if(regExp.test(input)){
                alert("格式正确");
            }else{
                alert("格式错误");
            }
        }
    </script>
    <button onclick="testReg()">测试正则表达式</button>
 </body>
</html>

技术分享图片

JS-regExp-正则表达式匹配2-6的数字

标签:document   输入   图片   inpu   test   lan   prompt   charset   utf-8   

原文地址:https://www.cnblogs.com/-hjj/p/9943324.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!