最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
C#常用正则验证函数示例
时间:2022-06-25 07:57:11 编辑:袖梨 来源:一聚教程网
1、Ip地址验证
代码如下 | 复制代码 |
/// /// Ip地址验证 /// publicstaticboolCheckIp(stringip) { boolresult =false; Regex ipReg =newRegex(@"^(d{1,2}|1dd|2[0-4]d|25[0-5]).(d{1,2}|1dd|2[0-4]d|25[0-5]).(d{1,2}|1dd|2[0-4]d|25[0-5]).(d{1,2}|1dd|2[0-4]d|25[0-5])$"); if(ipReg.IsMatch(ip)) { result =true; } returnresult; } |
2、价格验证
代码如下 | 复制代码 |
/// /// 价格验证 /// /// /// publicboolCheckPrice(stringpriceStr) { boolresult =false; Regex regex =newRegex(@"^d+(.d{1,2})?$", RegexOptions.IgnoreCase); Match match = regex.Match(priceStr); if(match.Success) { result =true; } returnresult; } |
3、正整数验证
代码如下 | 复制代码 |
/// /// 正整数验证 /// publicstaticboolCheckPositiveInteger(stringnumStr) { boolresult =false; Regex regex =newRegex(@"^[1-9]d*$", RegexOptions.IgnoreCase); Match match = regex.Match(numStr); if(match.Success) { result =true; } returnresult; } |
相关文章
- 《世界启元》S6赛季新英雄达尔文技能分析及配队推荐 06-16
- 《纸嫁衣3鸳鸯债》全章节超详细攻略 06-16
- 杠杆、流动性与多头:无人预见的山寨币反弹格局 06-16
- 《战争警戒》美军卡组搭配攻略 06-16
- 《职场浮生记》技能加点攻略 06-16
- 《职场浮生记》第一年全事件汇总 06-16