常用的验证
来源:互联网 发布:顾家沙发 知乎 编辑:程序博客网 时间:2024/04/28 04:47
namespace UtilityValidator
{
using System;
using System.Text.RegularExpressions;
public class Validators
{
//验证是否是有效日期
public static bool isValidDate(string strln)
{
if (Regex.IsMatch(strln, @"^[12]{1}(/d){3}[-][01]?(/d){1}[-][0123]?(/d){1}$"))
{
return (strln.CompareTo("1753-01-01") >= 0);
}
return false;
}
//验证Email
public static bool isValidEmail(string strln)
{
return Regex.IsMatch(strln,@"^([/w-/.]+)@((/[[0-9]{1,3}/.[0-9]{1,3}/.[0-9]{1,3}/.)|(([/w-]+/.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(/]?)$");
}
//验证传真
public static bool isValidFax(string strln)
{
return Regex.IsMatch(strln, @"^[+]{0,1}(/d){1,3}[ ]?([-]?((/d)|[ ]){1,12})+$");
}
//验证是否是有效移动电话号码
public static bool isValidMobil(string strln)
{
return Regex.IsMatch(strln, @"^(/d)+[-]?(/d){6,12}$");
}
//验证是否只含有字母
public static bool isValidOnllyChar(string strln)
{
return Regex.IsMatch(strln, "^[A-Za-z]+$");
}
//验证是否只含有汉字
public static bool isValidOnllyChinese(string strln)
{
return Regex.IsMatch(strln, @"^[/u4e00-/u9fa5]+$");
}
//验证是否只含有数字
public static bool isValidOnlyNumber(string strln)
{
return Regex.IsMatch(strln, "^[0-9]+$");
}
//验证是否是有效密码
public static bool isValidPassWord(string strln)
{
return Regex.IsMatch(strln, @"^(/w){6,20}$");
}
//验证是否是有效电话号码
public static bool isValidTel(string strln)
{
return Regex.IsMatch(strln, @"^[+]{0,1}(/d){1,3}[ ]?([-]?((/d)|[ ]){1,12})+$");
}
//验证是否是有效邮编号码
public static bool isValidZip(string strln)
{
return Regex.IsMatch(strln, "^[a-z0-9 ]{3,12}$");
}
}
}
- 常用的脚本验证
- 常用的验证
- 常用的验证
- 常用的验证
- 常用的js验证
- 常用的JS验证
- 常用的验证
- 常用的正则验证
- 常用的验证
- js 常用的验证
- 常用的验证
- 常用的正则验证
- 常用的一些验证
- rails常用的验证
- 常用的表单验证
- JAVA常用的验证(手机号的验证)
- Struts验证框架常用的验证规则
- 一个常用的表单验证
- 学习
- asp_net常用代码
- 突然觉得非常舒服
- 几个不错的蓝色调页面设计
- C#.net 用ODBC远程连接SQL Server2000---成功!
- 常用的验证
- 数据建模
- 重构 — 改善既有的类图设计 条款11:去除对聚合内部的引用
- Ajax 提交和验证
- 分手
- ajax和XMLHTTP原理
- Ajax在.NET中与Server控件的交互C#
- 一个输入框输入日期或时间,并验证输入是否有效
- Dev C++不同于VC的几点