Home > Web Front-end > JS Tutorial > JavaScript regular expression fuzzy matching IP address function example

JavaScript regular expression fuzzy matching IP address function example

高洛峰
Release: 2017-01-09 15:21:10
Original
1689 people have browsed it

本文实例讲述了javascript正则表达式模糊匹配IP地址功能。分享给大家供大家参考,具体如下:

function checkip() {
  var strIP = document.getElementById("accessip").value;
  var re = /^(\d{1,3}|\*)\.(\d{1,3}|\*)\.(\d{1,3}|\*)\.(\d{1,3}|\*)$/g //模糊匹配IP地址的正则表达式
  if(re.test(strIP)){
    if(RegExp.$1 == '*' && RegExp.$2 == '*' && RegExp.$3 == '*' && RegExp.$4 == '*'){
      return true;
    }
    if(RegExp.$1 < 256 && RegExp.$2 == &#39;*&#39; && RegExp.$3 == &#39;*&#39; && RegExp.$4 == &#39;*&#39;){
      return true;
    }
    if(RegExp.$1 < 256 && RegExp.$2 < 256 && RegExp.$3 == &#39;*&#39; && RegExp.$4 == &#39;*&#39;){
      return true;
    }
    if(RegExp.$1 < 256 && RegExp.$2 < 256 && RegExp.$3 < 256 && RegExp.$4 == &#39;*&#39;){
      return true;
    }
    if(RegExp.$1 < 256 && RegExp.$2 < 256 && RegExp.$3 < 256 && RegExp.$4 < 256){
      return true;
    }
  }
  return false;
}
Copy after login

希望本文所述对大家JavaScript程序设计有所帮助。

更多javascript正则表达式模糊匹配IP地址功能示例相关文章请关注PHP中文网!


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template