private bool IsMath(string StrData)
{
//1.IsNum
//输入的字符全是0~9
//Regex res = new Regex(@"^[0-9]*$");
//2.IsChar
//输入的字符全是大小写字母
// Regex res = new Regex(@"^[A-Za-z]+$");
//3.IsChinese
//输入字符全是中文
// Regex res = new Regex(@"^[\u4e00-\u9fa5]{0,}$");
//4.IsEmail
//输入电子邮件
// Regex res = new Regex(@"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$");
//5.IsInteger
//输入零或者非零数字
//Regex res = new Regex(@"^(0|[1-9][0-9]*)$");
//6.IsNumChar
//输入数字或者字母
// Regex res = new Regex(@"^[A-Za-z0-9]+$");
//7.IsNum_Char
//输入字符,数字,下划线
//Regex res = new Regex(@"^\w+$");
//8.IsUrl
//输入互联网网址
// Regex res = new Regex(@"^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$");
//9.IsMonth
//输入月份
// Regex res = new Regex(@"^(0?[1-9]|1[0-2])$");
//10.IsDate
//输入天数
//Regex res = new Regex("^((0?[1-9])|((1|2)[0-9])|30|31)$");
11.IsTel
//不能用
//Regex res = new Regex(@"^(\(\d{3,4}-)|\d{3.4}-)?\d{7,8}$");
//12.IsDouble
//输入且只能输入两位小数
// Regex res = new Regex(@"^[0-9]+(.[0-9]{2})?$");
//13.IsIp
//输入IP
//Regex res = new Regex(@"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$");
//14.IsQQ
//验证QQ号码,号码从1000开始
// Regex res = new Regex(@"[1-9][0-9]{4,}");
//15.IsPostCode
//验证是否邮政编码
// Regex res = new Regex(@"[1-9]\d{5}(?!\d)");
//16.IsIDNO
//验证身份证号码,后面不能为X/Y
//Regex res = new Regex(@"\d{15}|\d{18}");
//17.IsPInteger
// Regex res = new Regex(@"^[1-9]\d*$");
//18.IsNInteger
//验证负整数
//Regex res = new Regex(@"^-[1-9]\d*$");
//19.IsFloat
//验证浮点数
//必须要有小数点
//Regex res = new Regex(@"^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$");
//20.IsPFloat
//必须要有小数点
Regex res = new Regex(@"^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$");
return res.IsMatch(StrData);
}
}
}
/*
匹配特定数字:
^[1-9]\d*$ //匹配正整数
^-[1-9]\d*$ //匹配负整数
^-?[1-9]\d*$ //匹配整数
^[1-9]\d*|0$ //匹配非负整数(正整数 + 0)
^-[1-9]\d*|0$ //匹配非正整数(负整数 + 0)
^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$ //匹配正浮点数
^-([1-9]\d*\.\d*|0\.\d*[1-9]\d*)$ //匹配负浮点数
^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$ //匹配浮点数
^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$ //匹配非负浮点数(正浮点数 + 0)
^(-([1-9]\d*\.\d*|0\.\d*[1-9]\d*))|0?\.0+|0$ //匹配非正浮点数(负浮点数 + 0)
评注:处理大量数据时有用,具体应用时注意修正
匹配特定字符串:
^[A-Za-z]+$ //匹配由26个英文字母组成的字符串
^[A-Z]+$ //匹配由26个英文字母的大写组成的字符串
^[a-z]+$ //匹配由26个英文字母的小写组成的字符串
^[A-Za-z0-9]+$ //匹配由数字和26个英文字母组成的字符串
^\w+$ //匹配由数字、26个英文字母或者下划线组成的字符串
*/
{
//1.IsNum
//输入的字符全是0~9
//Regex res = new Regex(@"^[0-9]*$");
//2.IsChar
//输入的字符全是大小写字母
// Regex res = new Regex(@"^[A-Za-z]+$");
//3.IsChinese
//输入字符全是中文
// Regex res = new Regex(@"^[\u4e00-\u9fa5]{0,}$");
//4.IsEmail
//输入电子邮件
// Regex res = new Regex(@"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$");
//5.IsInteger
//输入零或者非零数字
//Regex res = new Regex(@"^(0|[1-9][0-9]*)$");
//6.IsNumChar
//输入数字或者字母
// Regex res = new Regex(@"^[A-Za-z0-9]+$");
//7.IsNum_Char
//输入字符,数字,下划线
//Regex res = new Regex(@"^\w+$");
//8.IsUrl
//输入互联网网址
// Regex res = new Regex(@"^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$");
//9.IsMonth
//输入月份
// Regex res = new Regex(@"^(0?[1-9]|1[0-2])$");
//10.IsDate
//输入天数
//Regex res = new Regex("^((0?[1-9])|((1|2)[0-9])|30|31)$");
11.IsTel
//不能用
//Regex res = new Regex(@"^(\(\d{3,4}-)|\d{3.4}-)?\d{7,8}$");
//12.IsDouble
//输入且只能输入两位小数
// Regex res = new Regex(@"^[0-9]+(.[0-9]{2})?$");
//13.IsIp
//输入IP
//Regex res = new Regex(@"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$");
//14.IsQQ
//验证QQ号码,号码从1000开始
// Regex res = new Regex(@"[1-9][0-9]{4,}");
//15.IsPostCode
//验证是否邮政编码
// Regex res = new Regex(@"[1-9]\d{5}(?!\d)");
//16.IsIDNO
//验证身份证号码,后面不能为X/Y
//Regex res = new Regex(@"\d{15}|\d{18}");
//17.IsPInteger
// Regex res = new Regex(@"^[1-9]\d*$");
//18.IsNInteger
//验证负整数
//Regex res = new Regex(@"^-[1-9]\d*$");
//19.IsFloat
//验证浮点数
//必须要有小数点
//Regex res = new Regex(@"^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$");
//20.IsPFloat
//必须要有小数点
Regex res = new Regex(@"^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$");
return res.IsMatch(StrData);
}
}
}
/*
匹配特定数字:
^[1-9]\d*$ //匹配正整数
^-[1-9]\d*$ //匹配负整数
^-?[1-9]\d*$ //匹配整数
^[1-9]\d*|0$ //匹配非负整数(正整数 + 0)
^-[1-9]\d*|0$ //匹配非正整数(负整数 + 0)
^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$ //匹配正浮点数
^-([1-9]\d*\.\d*|0\.\d*[1-9]\d*)$ //匹配负浮点数
^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$ //匹配浮点数
^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$ //匹配非负浮点数(正浮点数 + 0)
^(-([1-9]\d*\.\d*|0\.\d*[1-9]\d*))|0?\.0+|0$ //匹配非正浮点数(负浮点数 + 0)
评注:处理大量数据时有用,具体应用时注意修正
匹配特定字符串:
^[A-Za-z]+$ //匹配由26个英文字母组成的字符串
^[A-Z]+$ //匹配由26个英文字母的大写组成的字符串
^[a-z]+$ //匹配由26个英文字母的小写组成的字符串
^[A-Za-z0-9]+$ //匹配由数字和26个英文字母组成的字符串
^\w+$ //匹配由数字、26个英文字母或者下划线组成的字符串
*/