javascript正则表达式模糊匹配IP地址功能示例
作者:Mr__fang 时间:2024-06-12 00:28:10
本文实例讲述了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 == '*' && RegExp.$3 == '*' && RegExp.$4 == '*'){
return true;
}
if(RegExp.$1 < 256 && RegExp.$2 < 256 && RegExp.$3 == '*' && RegExp.$4 == '*'){
return true;
}
if(RegExp.$1 < 256 && RegExp.$2 < 256 && RegExp.$3 < 256 && RegExp.$4 == '*'){
return true;
}
if(RegExp.$1 < 256 && RegExp.$2 < 256 && RegExp.$3 < 256 && RegExp.$4 < 256){
return true;
}
}
return false;
}
希望本文所述对大家JavaScript程序设计有所帮助。
标签:javascript,正则表达式,模糊匹配
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
一篇文章带你入门SQL编程
2024-01-12 13:05:22
![](https://img.aspxhome.com/file/2023/0/109830_0s.png)
SQL SERVER 2012新增函数之逻辑函数IIF
2024-01-16 05:39:46
用Python生成N层的杨辉三角的实现方法
2022-12-20 16:27:09
![](https://img.aspxhome.com/file/2023/4/87604_0s.png)
关闭时刷新父窗口两种方法
2024-06-11 20:21:24
python中将字典形式的数据循环插入Excel
2023-07-05 01:49:19
![](https://img.aspxhome.com/file/2023/4/135454_0s.png)
在Django中URL正则表达式匹配的方法
2021-06-09 22:38:57
![](https://img.aspxhome.com/file/2023/2/94012_0s.jpg)
python处理大数字的方法
2022-06-09 02:19:03
SQL 提权 常用命令
2024-01-23 03:21:45
vue3组合式API中setup()概念和reactive()函数的用法
2024-05-22 10:42:13
![](https://img.aspxhome.com/file/2023/1/123221_0s.gif)
JavaScript模板入门介绍
2024-06-21 22:06:17
python sort、sort_index方法代码实例
2022-12-16 00:43:17
深入解析Go语言中for循环的写法
2024-05-22 10:11:44
![](https://img.aspxhome.com/file/2023/9/124009_0s.png)
sql cast,convert,QUOTENAME,exec 函数学习记录
2024-01-23 13:53:35
在Java程序中使用数据库的新方法
2024-01-20 00:55:35
MySql忘记密码修改方式适应5.7以上版本
2024-01-28 08:58:43
Django生成PDF文档显示网页上以及PDF中文显示乱码的解决方法
2022-01-05 22:02:07
![](https://img.aspxhome.com/file/2023/9/80649_0s.jpg)
零基础写python爬虫之urllib2中的两个重要概念:Openers和Handlers
2023-06-19 20:06:16
![](https://img.aspxhome.com/file/2023/7/85327_0s.png)
js滑动展开与折叠效果(收缩)
2007-10-09 13:17:00
浅谈MySQL中的自增主键用完了怎么办
2024-01-24 07:51:50
![](https://img.aspxhome.com/file/2023/3/118443_0s.png)
Python快速排序算法实例分析
2021-10-23 09:14:37
![](https://img.aspxhome.com/file/2023/4/72014_0s.png)