asp.net检验字符串是否满足指定正则表达式
///
/// 快速验证一个字符串是否符合指定的正则表达式。
///
/// 正则表达式的内容。
/// 需验证的字符串。
///是否合法的bool值。
public static bool QuickValidate(string _express, string _value)
{
if (_value == null) return false;
System.Text.RegularExpressions.Regex myRegex = new System.Text.RegularExpressions.Regex(_express);
if (_value.Length == 0)
{
return false;
}
return myRegex.IsMatch(_value);
}
使用:
///
/// 判断是否是数字,包括小数和整数。
///
/// 需验证的字符串。
///是否合法的bool值。
public static bool IsNumber(string _value)
{
return Validator.QuickValidate("^(0|([1-9]+[0-9]*))(.[0-9]+)?$", _value);
}
/// 快速验证一个字符串是否符合指定的正则表达式。
///
/// 正则表达式的内容。
/// 需验证的字符串。
///
public static bool QuickValidate(string _express, string _value)
{
if (_value == null) return false;
System.Text.RegularExpressions.Regex myRegex = new System.Text.RegularExpressions.Regex(_express);
if (_value.Length == 0)
{
return false;
}
return myRegex.IsMatch(_value);
}
使用:
///
/// 判断是否是数字,包括小数和整数。
///
/// 需验证的字符串。
///
public static bool IsNumber(string _value)
{
return Validator.QuickValidate("^(0|([1-9]+[0-9]*))(.[0-9]+)?$", _value);
}
以上就是asp.net验证一个字符串是否符合指定的正则表达式的详细内容,更多请关注0133技术站其它相关文章!