常用正则表达式

英文单词

string Match = "^\\w+$";

中文

string  Match = "[\u4E00-\u9FA5]+";

Email 地址

// 方案1
string Match = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*.\\w+([-.]\\w+)*";
// 方案2
string Match = "^[\\w]+(\\.\\w)@[\\w]+(\\.[\\w]+)*\\.(com|cn|net)$";

中国电话号码

string Match = "0\\d{2,3}-\\d{7,8}";

中国移动电话

string Match = "1[3|5|8][0-9]-\\d{8}";

电话号码正则表达式(支持手机号码,3-4位区号,7-8位直播号码,1-4位分机号)

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

((\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}))$)

// 方案2
// 中国电信号段
// 133、149、153、173、177、180、181、189、199
// 中国联通号段
// 130、131、132、145、155、156、166、175、176、185、186
// 中国移动号段
// 134(0 - 8)、135、136、137、138、139、147、150、151、152、157、158、159、178、182、183、184、187、188、
// 198
// 其他号段
// 14号段以前为专属号段,如的是145,的是147等等。
// 电信:1700、1701、1702
// 移动:1703、1705、1706
// 1704、1707、1708、1709、17
string Match = "^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$";

中国身份证号

string Match = "\\d{17}[0-9|x|X]|\\d{15}";

中国邮政编码

string Match = "\\d{6}";

QQ号

string Match = "[1-9][0-9]{4,}";

6到30位 数字 + 字符 + _,常用于用户名注册

string Match= " ^[a-zA-Z][a-zA-Z0-9_]{6,29}$";

5到20位 数字 + 字符 + _,常用于用户名注册

string Match = "^[a-zA-Z][a-zA-Z0-9_]{5,19}$";

数字 + 字符 + _,且必须已字母开头

String Match = "^[a-zA-Z][a-zA-Z0-9_]+$";

数字 + 字母 组合

string Match = "^[A-Za-z0-9]+$";

字母组合

string Match = "^[A-Za-z]+$";

大写字母组合

string Match = "^[A-Z]+$";

小写字母组合

string Match = "^[a-z]+$";

双字节

string Match = "[^x00-xff]+";

HTML 标签

string Match = "<(\\S*?)[^>]*>.*?|<.*? />";

IP 地址

string Match = "((25[0-5])|(2[0-4]\\d)|(1\\d{2})|([1-9]\\d)|(\\d)).((25[0-5])|(2[0-4]\\d)|(1\\d{2})|([1-9]\\d)|(\\d)).((25[0-5])|(2[0-4]\\d)|(1\\d{2})|([1-9]\\d)|(\\d)).((25[0-5])|(2[0-4]\\d)|(1\\d{2})|([1-9]\\d)|(\\d))";

URL地址: 包括 http, ftp 等

string Match = "[a-zA-z]+://[^s]*";

HTTP URL

string Match = "http(s)?://[^s]+";

Internet URL

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

数字

string Match = "^[0-9]+$";

正数

string Match = "^[1-9]\\d*$";

非正数

string Match = "^-[1-9]\\d*|0$";

负数

string Match = "^-[1-9]\\d*$";

非负数

string Match = "^[1-9]\\d*|0$";

整数

string Match = "^-?[1-9]\\d*$";

浮点数

string Match = "^-?([1-9]\\d*.\\d*|0.\\d*[1-9]\\d*|0?.0+|0)$";

正浮点数

string Match = "^[1-9]\\d*.\\d*|0.\\d*[1-9]\\d*$";

非正浮点数

string Match = "^(-([1-9]\\d*.\\d*|0.\\d*[1-9]\\d*))|0?.0+|0$";

负浮点数

string Match = "^-([1-9]\\d*.\\d*|0.\\d*[1-9]\\d*)$";

非负浮点数

string Match = "^[1-9]\\d*.\\d*|0.\\d*[1-9]\\d*|0?.0+|0$";

空行

string Match = "\n\\s*\r";

空字符

string Match = "^\\s*|\\s*$";

关键字标签正则:仅允许输入中文、英文(含大小写)、数字,输入内容必须以逗号隔开(含中英文逗号),但不能以逗号开头或结尾

// 正确格式示例:99,AB,示例,ss,呵呵
string Match = "^([a-zA-Z0-9\\u4e00-\\u9fa5]+[,|,])*[a-zA-Z0-9\\u4e00-\\u9fa5]+$";

能输入有1~3位小数的正实数(包含0)

string Match = "^[0-9]+(\\.[0-9]{1,3})?$";
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值