国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

幾個C#常用正則表達式的總結

2024-07-10 13:13:25
字體:
來源:轉載
供稿:網友
using System; 
using System.Text.RegularExpressions; 

namespace CommonTools 

/**//// <summary> 
/// RegexLib 的摘要說明。 
/// </summary> 
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,@"^2/d{3}-(?:0?[1-9]|1[0-2])-(?:0?[1-9]|[1-2]/d|3[0-1])(?:0?[1-9]|1/d|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}|1/d/d|2[0-4]/d|25[0-5])/.(/d{1,2}|1/d/d|2[0-4]/d|25[0-5])/.(/d{1,2}|1/d/d|2[0-4]/d|25[0-5])/.(/d{1,2}|1/d/d|2[0-4]/d|25[0-5])$"); 



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 拉萨市| 二连浩特市| 姚安县| 调兵山市| 潢川县| 甘孜| 澄迈县| 新巴尔虎右旗| 瓦房店市| 榆社县| 盐城市| 台中县| 庄浪县| 石屏县| 武陟县| 临安市| 镇沅| 西充县| 原平市| 苗栗市| 垣曲县| 清水河县| 鹤庆县| 竹北市| 拜泉县| 四平市| 益阳市| 绵竹市| 云南省| 布尔津县| 武山县| 和政县| 普洱| 洪湖市| 东台市| 海南省| 隆安县| 柯坪县| 樟树市| 神农架林区| 海兴县|