javascript 正则表达式判断IP地址合法性

                 <html>
<head>
<title>test</title>
<script type="text/javascript">
function checkIP(value){
  var pattern = /^/d{1,3}(/./d{1,3}){3}$/;
  if (!pattern.exec(value)) {
    alert('please input valid ip address');
    return false;
  }
 
  var ary = value.split('.');
  for(key in ary)
  {
    if (parseInt(ary[key]) > 255){
      alert('please input valid ip address');
      return false;
    }
  }
 
  alert('valid ip address');
  return true ;
}
</script>
</head>
<body>
<input type="text" name="ip" onchange="checkIP(this.value);"/>
</body>
</html>           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

猜你喜欢

转载自blog.csdn.net/cfhgcvb/article/details/86483485