C#验证字符串是否是数字、传真、邮政编码、网址或者电子邮件
2015-07-24 10:33
351 查看
#region 验证数字
public static bool strIsNum(string str)
{
return Regex.IsMatch(str, "^[0-9]*$");
}
#endregion
#region 验证传真
public static bool strIsFax(string str)
{
return Regex.IsMatch(str, @"86-\d{3,4}-\d{7,8}");
}
#endregion
#region 验证邮政编码
public static bool strIsPostCode(string str)
{
return Regex.IsMatch(str, @"\d{6}");
}
#endregion
#region 验证电子邮件
public static bool strIsEmail(string str)
{
return Regex.IsMatch(str, @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
}
#endregion
#region 验证网址
public static bool strIsNAddress(string str)
{
return Regex.IsMatch(str, @"http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?");
}
#endregion
public static bool strIsNum(string str)
{
return Regex.IsMatch(str, "^[0-9]*$");
}
#endregion
#region 验证传真
public static bool strIsFax(string str)
{
return Regex.IsMatch(str, @"86-\d{3,4}-\d{7,8}");
}
#endregion
#region 验证邮政编码
public static bool strIsPostCode(string str)
{
return Regex.IsMatch(str, @"\d{6}");
}
#endregion
#region 验证电子邮件
public static bool strIsEmail(string str)
{
return Regex.IsMatch(str, @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
}
#endregion
#region 验证网址
public static bool strIsNAddress(string str)
{
return Regex.IsMatch(str, @"http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?");
}
#endregion
相关文章推荐
- 数据库链接字符串查询网站
- c#调用COM组件
- Flex字符串比较 还有Flex字符串操作
- C#实现把指定数据写入串口
- C#中抽象方法与虚拟方法的区别
- c#中虚函数的相关使用方法
- C#实现多线程的同步方法实例分析
- C#中尾递归的使用、优化及编译器优化
- C#通用邮件发送类分享
- C#中this的用法集锦
- C#.NET获取拨号连接的宽带连接方法
- C#实现AddRange为数组添加多个元素的方法
- C#中Equality和Identity浅析
- C#生成饼形图及添加文字说明实例代码
- C#判等对象是否相等的方法汇总
- C#简单的向量用法实例教程
- C#实现基于链表的内存记事本实例
- C#托管堆对象实例包含内容分析
- C#实现按照指定长度在数字前补0方法小结
- C# 通过 inline-asm 解决嵌入x86汇编