C# 常用正则
收录的有用的的正则表达式
- private static string ValidateChinaese = @"[/u4e00-/u9fa5]";//中文验证
- private static string ValidateDoubleChar = @"[^/x00-/xff]";//匹配双字节
- private static string ValidateBlankChar = @"/n/s*/r";//空白字符
- private static string ValidateHtml = @"<(/S*?)[^>]*>.*?<//1>|<.*? />";//匹配HTML格式
- private static string ValidateStartEndBlank = @"^/s*|/s*$";//匹配首尾是空白字符
- private static string ValidateEmail = @"/w+([-+.]/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*";//匹配电子邮件
- private static string ValidateUrl = @"[a-zA-z]+://[^/s]*";//匹配url地址
- private static string ValidateUserID = @"^[a-zA-Z][a-zA-Z0-9_]{4,15}$";//匹配用户名 长度是4-15的长度 可控性差 但是 可以当成是一个事例来写正则表达式
- private static string ValidateTel = @"(86-)?/d{3}-/d{8}|/d{4}-/d{8}";//国内的电话号码 这也可以用于国际中 +86 可以不输
- private static string Validate10086 = @"^1(3[4-9]|5[012789]|8[78])/d{8}$";//移动手机
- private static string Valiate10010 = @"^1(3[0-2]|5[56]|8[56])/d{8}$";//中国联通
- private static string Valiate10000 = @"^1(3[0-2]|5[56]|8[56])/d{8}$";//中国电信
- private static string Validate100002=@"^18[09]/d{8}$";//电信号还有180和189的号
- private static string ValiateCDMA = @"^1[35]3/d{8}$";//CDMA 用户
- private static string ValidateQQ = @"[1-9][0-9]{4,}";//腾讯QQ号码
- private static string ValidatePost = @"[1-9]/d{5}(?!/d)";//邮政编码
- private static string ValidateIDCard = @"/d{15}|/d{18}";//身份证验证
- private static string ValidateIpAddress = @"/d+/./d+/./d+/./d+";//IP地址验证对象
- private static string ValidatePlus = @"^[1-9]/d*$"; //匹配正整数
- private static string ValidateNegative = @"^-[1-9]/d*$"; //匹配负整数
- private static string ValidateInteger = @"^-?[1-9]/d*$"; //匹配整数
- private static string ValidateNotInteger = @"^[1-9]/d*|0$"; //匹配非负整数(正整数 + 0)
- private static string ValidateNotPlus = @"^-[1-9]/d*|0$"; //匹配非正整数(负整数 + 0)
- private static string ValidateFloat = @"!^[1-9]/d*/./d*|0/./d*[1-9]/d*$"; //匹配正浮点数
- private static string ValidateNotFloat = @"^-([1-9]/d*/./d*|0/./d*[1-9]/d*)$"; //匹配负浮点数
只有不断学习,才可进步。

浙公网安备 33010602011771号