栏目分类:
子分类:
返回
文库吧用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
文库吧 > IT > 软件开发 > 后端开发 > asp

几个C#常用正则表达式的总结

asp 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

几个C#常用正则表达式的总结

using System; 
using System.Text.Regularexpressions; 

namespace CommonTools 

///  
/// RegexLib 的摘要说明。 
/// 
 
public class RegexLib 


//验证Email地址 
public static bool IsValidEmail(string strIn) 

// Return true if strIn is in valid e-mail format. 
return Regex.IsMatch(strIn, @"^([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$"); 

//dd-mm-yy 的日期形式代替 mm/dd/yy 的日期形式。 
public static string MDYToDMY(String input) 

return Regex.Replace(input,"\b(?\d{1,2})/(?\d{1,2})/(?\d{2,4})\b","${day}-${month}-${year}"); 

//验证是否为小数 
public static bool IsValidDecimal(string strIn) 

return Regex.IsMatch(strIn,@"[0].d{1,2}|[1]"); 

//验证是否为电话号码 
public static bool IsValidTel(string strIn) 

return Regex.IsMatch(strIn,@"(d+-)?(d{4}-?d{7}|d{3}-?d{8}|^d{7,8})(-d+)?"); 

//验证年月日 
public static bool IsValidDate(string strIn) 

return Regex.IsMatch(strIn,@"^2d{3}-(?:0?[1-9]|1[0-2])-(?:0?[1-9]|[1-2]d|3[0-1])(?:0?[1-9]|1d|2[0-3]):(?:0?[1-9]|[1-5]d):(?:0?[1-9]|[1-5]d)$"); 

//验证后缀名 
public static bool IsValidPostfix(string strIn) 

return Regex.IsMatch(strIn,@".(?i:gif|jpg)$"); 

//验证字符是否再4至12之间 
public static bool IsValidByte(string strIn) 

return Regex.IsMatch(strIn,@"^[a-z]{4,12}$"); 

//验证IP 
public static bool IsValidIp(string strIn) 

return Regex.IsMatch(strIn,@"^(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])$"); 




转载请注明:文章转载自 www.wk8.com.cn
本文地址:https://www.wk8.com.cn/it/60009.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 wk8.com.cn

ICP备案号:晋ICP备2021003244-6号