using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace Utility.UI
{
///<summary>
///<Author>jilongliang</Author>
///<Date>2012/9/7</Date>
///<Email >jilongliang@sina.com</Email >
///<Description>验证类</Description>
///</summary>
public class ValidateHelper
{
private static Regex RegNumber = new Regex("^[0-9]+$");//数字字符串
private static Regex RegNumberSign = new Regex("^[+-]?[0-9]+$");//数字字符串
private static Regex RegDecimal = new Regex("^[0-9]+[.]?[0-9]+$");//浮点数
private static Regex RegDecimalSign = new Regex("^[+-]?[0-9]+[.]?[0-9]+$"); //等价于^[+-]?\d+[.]?\d+$
private static Regex RegEmail = new Regex("^[\\w-]+@[\\w-]+\\.(com|net|org|edu|mil|tv|biz|info)$");//w 英文字母或数字的字符串,和 [a-zA-Z0-9] 语法一样
private static Regex RegCHZN = new Regex("[\u4e00-\u9fa5]");//中文
private static Regex RegQQ = new Regex("[1-9][0-9]{4,}");//匹配腾讯QQ号
private static Regex RegTel = new Regex("d{3}-d{8}|d{4}-d{7}");//Tel匹配国内电话号码
private static Regex RegURL = new Regex("[a-zA-z]+://[^s]*");//URL
private static Regex RegZipCode = new Regex("[1-9]d{5}(?!d)");//CN 邮政编码
private static Regex RegIDCard = new Regex("d{15}|d{18}");//匹配身份证:d{15}|d{18}
private static Regex RegHTML = new Regex("<(S*?)[^>]*>.*?|<.*? />");//匹配HTML标记的正则表达式:<(S*?)[^>]*>.*?|<.*? />
private static Regex RegPassWord = new Regex("^[a-zA-Z]w{5,17}$"); //验证用户密码:“^[a-zA-Z]w{5,17}$”正确格式为:以字母开头,长度在6-18之间
private static Regex Reg26A_Z = new Regex("^[A-Za-z]+$");//只能输入由26个英文字母组成的字符串:“^[A-Za-z]+$”
private static Regex Reg26Large_A_Z = new Regex("^[A-Z]+$");//只能输入由26个大写英文字母组成的字符串:“^[A-Z]+$”
private static Regex Reg26Small_A_Z = new Regex("^[a-z]+$");//只能输入由26个小写英文字母组成的字符串:“^[a-z]+$”
private static Regex Reg0_9_A_Z = new Regex("^[A-Za-z0-9]+$");//只能输入由数字和26个英文字母组成的字符串:“^[A-Za-z0-9]+$”
private static Regex Reg0_9_A_Z_ = new Regex("^w+$");//只能输入由数字、26个英文字母或者下划线组成的字符串:“^w+$”
///<summary>
///无参数构造方法
///</summary>
public ValidateHelper()
{
}
///<summary>
///是否数字字符串
///</summary>
///<param name="inputData">输入字符串</param>
///<returns></returns>
public static bool IsNumber(string inputData)
{
Match m = RegNumber.Match(inputData);
return m.Success;
}
///<summary>
///是否数字字符串 可带正负号
///</summary>
///<param name="inputData">输入字符串</param>
///<returns></returns>
public static bool IsNumberSign(string inputData)
{
Match m = RegNumberSign.Match(inputData);
return m.Success;
}
///<summary>
///是否是浮点数
///</summary>
///<param name="inputData">输入字符串</param>
///<returns></returns>
public static bool IsDecimal(string inputData)
{
Match m = RegDecimal.Match(inputData);
return m.Success;
}
///<summary>
///是否是浮点数 可带正负号
///</summary>
///<param name="inputData">输入字符串</param>
///<returns></returns>
public static bool IsDecimalSign(string inputData)
{
Match m = RegDecimalSign.Match(inputData);
return m.Success;
}
#region中文检测
///<summary>
///检测是否有中文字符
///</summary>
///<param name="inputData"></param>
///<returns></returns>
public static bool IsHasCHZN(string inputData)
{
Match m = RegCHZN.Match(inputData);
return m.Success;
}
#endregion
#region邮件地址
///<summary>
///是否是浮点数 可带正负号
///</summary>
///<param name="inputData">输入字符串</param>
///<returns></returns>
public static bool IsEmail(string inputData)
{
Match m = RegEmail.Match(inputData);
return m.Success;
}
#endregion
///<summary>
///验证是否合法的URL
///</summary>
///<param name="InputStr"></param>
///<returns></returns>
public static bool IsURL(string InputStr)
{
Match m = RegURL.Match(InputStr);
return m.Success;
}
///<summary>
///验证电话号码是否合法
///</summary>
///<param name="InputStr"></param>
///<returns></returns>
public static bool IsTelNumber(string InputStr)
{
Match m = RegTel.Match(InputStr);
return m.Success;
}
///<summary>
///验证邮政编码
///</summary>
///<param name="InputStr"></param>
///<returns></returns>
public static bool IsZipCode(string InputStr)
{
Match m = RegZipCode.Match(InputStr);
return m.Success;
}
///<summary>
///验证QQ号
///</summary>
///<param name="InputStr"></param>
///<returns></returns>
public static bool IsQQ(string InputStr)
{
Match m = RegQQ.Match(InputStr);
return m.Success;
}
///<summary>
///验证身份证
///</summary>
///<param name="InputStr"></param>
///<returns></returns>
public static bool IsIDCard(string InputStr)
{
Match m = RegIDCard.Match(InputStr);
return m.Success;
}
///<summary>
///验证用户密码
///</summary>
///<param name="InputStr"></param>
///<returns></returns>
public static bool IsPassWord(string InputStr)
{
Match m = RegPassWord.Match(InputStr);
return m.Success;
}
///<summary>
///验证只能输入由26个英文字母组成的字符串
///</summary>
///<param name="InputStr"></param>
///<returns></returns>
public static bool Is26A_Z(string InputStr)
{
Match m = Reg26A_Z.Match(InputStr);
return m.Success;
}
///<summary>
///只能输入由26个大写英文字母组成的字符串
///</summary>
///<param name="InputStr"></param>
///<returns></returns>
public static bool Is26Large_A_Z(string InputStr)
{
Match m = Reg26Large_A_Z.Match(InputStr);
return m.Success;
}
///<summary>
///只能输入由26个小写英文字母组成的字符串
///</summary>
///<param name="InputStr"></param>
///<returns></returns>
public static bool Is26Small_A_Z(string InputStr)
{
Match m = Reg26Small_A_Z.Match(InputStr);
return m.Success;
}
///<summary>
///只能输入由数字和26个英文字母组成的字符串
///</summary>
///<param name="InputStr"></param>
///<returns></returns>
public static bool Is0_9_AZ_Str(string InputStr)
{
Match m = Reg0_9_A_Z.Match(InputStr);
return m.Success;
}
///<summary>
///只能输入由数字和26个英文字母组成的字符串和下划线
///</summary>
///<param name="InputStr"></param>
///<returns></returns>
public static bool Is0_9_A_Z_Str(string InputStr)
{
Match m = Reg0_9_A_Z_.Match(InputStr);
return m.Success;
}
}
}
相关推荐
validate 通用Ajax无刷新表单验证类validate 通用Ajax无刷新表单验证类
validate 通用Ajax无刷新表彰验证类validate 通用Ajax无刷新表彰验证类
最新实用的Validate通用表单验证Jquery插件
validate 通用Ajax无刷新表单验证类(JavaScript)
通用表单验证Jquery插件
一个简单的validate表单验证例子,包含的通用为空、格式(邮政编码等)、自定义验证、ajax验证……
Validate通用表单验证Jquery插件.zip。前端js实现 表单多种验证,不需要请求服务器,正则表达式匹配手机号、邮箱、IP地址、身份证、中文等。
jQuery带Tips动画提示通用表单验证插件下载(jquery validate),动画效果漂亮
javascript,小程序,uni-app通用的验证类,内置常用的验证方法。。//使用用方法 /* *valit_rule验证规则 *value,验证数据form *true ,一次性全部检测完 / //var vali_result = validate.check(this.data.valit_rule,...
1.验证的表单元素,需要添加 class 名 : vf-validate 方开启验证; 2.当使用 vf_func 调用其他验证函数时,会传入“当前元素”;且需要在验证函数中返回验证状态:true(验证成功),其他或false皆为验证失败 * ...
忙了一天,总算是完成了 因为现在的项目中使用了很多struts标签,原来网上流传的validate.js不能用了,所以狠下心来修改了validate,用了不同的方法实现了通用验证,并且与标签分离,可以与struts标签结合使用
通用验证模块本来只作为内部使用,其中用到的17种正则表达式。 html的dom结构一直不能解决继承问题,也正因为缺少了继承,导致了扩展性差。在面向对象的语言中, 我可以从一个文本框类继承下来一个类,这个新类我...
JavaScript写的Validate通用表彰验证代码,
表单中任意域加上emptyInfo属性将对此域是否为空进行验证(可以和最大长度验证\一般验证方式同时使用)。 无此属性视为此域允许空值。 如:字段不能为空!"> 3、最大长度验证(可以和空值验证、一般验证方式同时...
基于jQuery表单验证,非常通用的表单验证,在需要的表单原素上添加上相应的正则和错误提示的内容,就可以愉快的使用了 注意设置了readonly、disabled,都会对其进行验证,一般用于该节点不需要被输入(如在其它层...
jquery通用验证插件,可使用pc或移动端,简单易用。 页面中引入插件后,表单标签中加入对应插件属性。如 <input name="realName" data-required type="text"></input> 加入了data-required属性 在js函数中...
内容索引:脚本资源,Ajax/JavaScript,validate,Ajax,无刷新,表单验证 validate 通用Ajax无刷新表彰验证类(JavaScript),自带各种可能出现 的表单验证类型,不刷新网页即可验证输入的正确性,一位JS高手特此借助...
前端项目-angular-ui-validate,NGModel的通用验证程序。
Validate用户注册表单验证插件是一款基于jQuery实现的通用表单验证插件,有DEMO实例,简单实用。可以进行账号、密码、电话、手机、IP、URL、电子邮箱、中文姓名、身份证号码、数字验证码、自定义验证规则-数字等用户...
基于jquery的表单验证通用性、简化了开发的难度。