常用正则表达式
来源:互联网 发布:蛋炒饭影评知乎 编辑:程序博客网 时间:2024/05/21 11:14
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])$");
}
}
}
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])$");
}
}
}
- 【正则】常用正则表达式
- 正则表达式-常用正则表达式
- 正则表达式 常用正则表达式
- 正则表达式---常用的正则
- 正则表达式---常用的正则
- 【正则】常用正则表达式收集
- 正则大全 常用正则表达式
- 正则表达式 常用的正则
- .net正则表达式(常用表达式)
- 正则表达式中常用表达式
- 常用的正则表达式
- 常用正则表达式
- 常用的正则表达式
- 常用正则表达式参考
- 常用正则表达式收藏
- 常用C#正则表达式
- 常用正则表达式
- 常用正则表达式实例
- 日本的开发习惯 第三篇
- 编译器优化 → C关键字volatile → memory破坏描述符zz
- 黑客常用命令大全
- StockVault
- 在emf 中保存特殊字符
- 常用正则表达式
- 具体的*P的意思
- VC++术语解释
- 根据某条记录的关键字值,如何从newxy动态formBean的记录集中获得这条记录
- DotNetBar 6.6.0.1 for VS2003
- ATL介绍
- ajax中 同一页面中 区别 更新多个区域的关键
- Sohu主编方刚: 网络编辑该怎么做?
- MFC程序的来龙去脉