几个C#常用正则表达式的总结
来源:互联网 发布:软件试用情况总结报告 编辑:程序博客网 时间:2024/05/16 00:54
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,@"^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])$");
}
}
}
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,@"^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])$");
}
}
}
- 几个C#常用正则表达式的总结
- 几个C#常用正则表达式的总结
- 几个C#常用正则表达式的总结
- 几个C#常用正则表达式
- c#常用的正则表达式,常用正则表达式总结
- c#一些常用的正则表达式总结
- c#一些常用的正则表达式总结
- c# 中常用的正则表达式总结
- 几个常用的正则表达式
- 常用的几个正则表达式
- 常用的几个正则表达式
- 几个常用的正则表达式
- 几个常用的正则表达式
- C#常用正则表达式总结
- 整理几个C#常用正则表达式
- c#常用的正则表达式,其实对所有语言都通用,常用正则表达式总结
- c#几个正则表达式
- C#的常用正则表达式
- 一个 超 超 超经典的短篇小说
- xp下IIS连接数限制修改方法
- 开张大吉
- Tomcat和Velocity配置
- HTML标记
- 几个C#常用正则表达式的总结
- 关于C运行时库
- 第十八篇 oracle硬件配置架构之二:网络主机结构(整理)
- CSS样式
- war文件的问题
- 获取SAP标准函数的说明(含参数和异常)
- [转][荐]小菜编程成长记系列
- C++/C试题
- VC++ListCtrl控件(陆)