码迷,mamicode.com
首页 > 其他好文 > 详细

正则表达式 判断 ip:端口 形式

时间:2016-07-19 23:42:14      阅读:864      评论:0      收藏:0      [点我收藏+]

标签:

<html>
<head>
</head>
<body>
    
ip:port<input type="" name="zhzh" placeholder="ip:port" id="zhzh">
<button onclick="btn()" value="submit">test</button>

<script type="text/javascript">
      ip_ip = ‘(25[0-5]|2[0-4]\\d|1\\d\\d|\\d\\d|\\d)‘;
    ip_ipdot = ip_ip + ‘\\.‘;
    ip_port = ‘(:(\\d\\d\\d\\d|\\d\\d\\d|\\d\\d|\\d))?‘;
    isIPaddress = new RegExp(‘^‘+ip_ipdot+ip_ipdot+ip_ipdot+ip_ip+ip_port+‘$‘);
    function btn(){
        var inputValue=document.getElementById("zhzh").value;
        if (!isIPaddress.test(inputValue)) {
            console.log("wrong");
        }
    }
    //10.10.117.119 
</script>
</body>
</html>

 

正则表达式 判断 ip:端口 形式

标签:

原文地址:http://www.cnblogs.com/zyjzz/p/5686493.html

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