C# 常用正则

收录的有用的的正则表达式 

 

[c-sharp] view plain copy
 
  1. private static string ValidateChinaese = @"[/u4e00-/u9fa5]";//中文验证  
  2.  private static string ValidateDoubleChar = @"[^/x00-/xff]";//匹配双字节  
  3.  private static string ValidateBlankChar = @"/n/s*/r";//空白字符  
  4.  private static string ValidateHtml = @"<(/S*?)[^>]*>.*?<//1>|<.*? />";//匹配HTML格式  
  5.  private static string ValidateStartEndBlank = @"^/s*|/s*$";//匹配首尾是空白字符  
  6.  private static string ValidateEmail = @"/w+([-+.]/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*";//匹配电子邮件  
  7.  private static string ValidateUrl = @"[a-zA-z]+://[^/s]*";//匹配url地址  
  8.  private static string ValidateUserID = @"^[a-zA-Z][a-zA-Z0-9_]{4,15}$";//匹配用户名 长度是4-15的长度 可控性差 但是 可以当成是一个事例来写正则表达式  
  9.  private static string ValidateTel = @"(86-)?/d{3}-/d{8}|/d{4}-/d{8}";//国内的电话号码 这也可以用于国际中 +86 可以不输  
  10.  private static string Validate10086 = @"^1(3[4-9]|5[012789]|8[78])/d{8}$";//移动手机  
  11.  private static string Valiate10010 = @"^1(3[0-2]|5[56]|8[56])/d{8}$";//中国联通  
  12.  private static string Valiate10000 = @"^1(3[0-2]|5[56]|8[56])/d{8}$";//中国电信  
  13.  private static string Validate100002=@"^18[09]/d{8}$";//电信号还有180和189的号  
  14.  private static string ValiateCDMA = @"^1[35]3/d{8}$";//CDMA 用户  
  15.  private static string ValidateQQ = @"[1-9][0-9]{4,}";//腾讯QQ号码  
  16.  private static string ValidatePost = @"[1-9]/d{5}(?!/d)";//邮政编码  
  17.  private static string ValidateIDCard = @"/d{15}|/d{18}";//身份证验证  
  18.  private static string ValidateIpAddress = @"/d+/./d+/./d+/./d+";//IP地址验证对象  
  19.  private static string ValidatePlus = @"^[1-9]/d*$";    //匹配正整数  
  20.  private static string ValidateNegative = @"^-[1-9]/d*$";   //匹配负整数  
  21.  private static string ValidateInteger = @"^-?[1-9]/d*$";   //匹配整数  
  22.  private static string ValidateNotInteger = @"^[1-9]/d*|0$";  //匹配非负整数(正整数 + 0)  
  23.  private static string ValidateNotPlus = @"^-[1-9]/d*|0$";   //匹配非正整数(负整数 + 0)  
  24.  private static string ValidateFloat = @"!^[1-9]/d*/./d*|0/./d*[1-9]/d*$";  //匹配正浮点数  
  25.  private static string ValidateNotFloat = @"^-([1-9]/d*/./d*|0/./d*[1-9]/d*)$";  //匹配负浮点数 
posted @ 2016-07-29 14:42  TheSongOfSoul  阅读(128)  评论(0)    收藏  举报