正则表达式

C#
Regex re = new Regex(@"表达式");
if (!re.IsMatch(tbQQ.Text.Trim()))
{
        sb.Append(lbQQ.Text.Trim() + "格式不正确\r\n");
}


//整数
"^([+-]?)\\d+$"

//正整数
"^([+]?)\\d+$"                       

//负整数
"^-[0-9]*[1-9][0-9]*$"                            

//数字
"^([+-]?)\\d*\\.?\\d+$"                 

//正数
"^([+]?)\\d*\\.?\\d+$"

//负数
"^-\\d*\\.?\\d+$"                    

非负浮点数(正浮点数 + 0)

^\d+(\.\d+)?$

正浮点数   

^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$
非正浮点数(负浮点数 + 0) 

^((-\d+(\.\d+)?)|(0+(\.0+)?))$
负浮点数  

^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$
浮点数  

^(-?\d+)(\.\d+)?   

//邮件
"^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$"

//颜色
"^#[a-fA-F0-9]{6}"     

//URL
"^http(s)?://(?!([\w-]+\.[\w-]+$))([\w-]+\.)+[\w-]+(/[\w-   ./?%&=]*)?$"

//仅中文
"^[\\u4E00-\\u9FA5\\uF900-\\uFA2D]+$"

//仅ACSII字符
"^[\\x00-\\xFF]+$"

//邮编
"^\\d{6}$"                       

//手机
电话号码正则表达式(支持手机号码,3-4位区号,7-8位直播号码,1-4位分机号) ((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)

匹配格式:
11位手机号码
3-4位区号,7-8位直播号码,1-4位分机号
如:12345678901、1234-12345678-1234

//ip地址
"^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$"

//非空
"^\\S+$"

//图片
"(.*)\\.(jpg|bmp|gif|ico|pcx|jpeg|tif|png|raw|tga)$"

//压缩文件
"(.*)\\.(rar|zip|7zip|tgz)$"

posted @ 2012-02-09 16:30  一篮饭特稀  阅读(207)  评论(0编辑  收藏  举报