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


<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>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM