1.是否为数字
Regex rx = new Regex(@"^[+-]?[0123456789]*[.]?[0123456789]*$");
2.是否只包含字母与数字
Regex rx = new Regex(@"^[a-zA-Z0-9-]*$");
3.是否是身份证
Regex rx = new Regex(@"^[0123456789]{15,18}$");
最后一位带X:Regex rx = new Regex(@"^(/d{15}$|^/d{18}$|^/d{17}(/d|X|x))$");
4.是否是IP地址
Regex rx = new Regex(@"d+.d+.d+.d+");
考虑网段:Regex rx = new Regex(@"(?:(?:25[0-5]|2[0-4]/d|[01]?/d?/d)/.){3}(?:25[0-5]|2[0-4]/d|[01]?/d?/d)");
5.是否是URL地址
Regex rx = new Regex(@"[a-zA-z]+://[^s]*");
6.是否是汉字
Regex rx = new Regex(@"u4e00-u9fa5");
7.是否是电话号(中国地区)
Regex rx = new Regex(@"((d{3,4})|d{3,4}-)?d{7,8}(-d{3})*");
8.是否是邮编
Regex rx = new Regex(@"^[0123456789]{6}$");
9.是否是邮箱
Regex rx = new Regex(@"w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*");
10.是否是整数
Regex rx = new Regex(@"^[0123456789]+$");
原文链接:https://www.f2er.com/regex/363163.html