常用的服務(wù)器端正則式
1、非負整數(shù):”^\d+$”
2、正整數(shù):”^[0-9]*[1-9][0-9]*$”
3、非正整數(shù):”^((-\d+)|(0+))$”
4、負整數(shù):”^-[0-9]*[1-9][0-9]*$”
5、整數(shù):”^-?\d+$”
6、非負浮點數(shù):”^\d+(\.\d+)?$”
7、正浮點數(shù):”^((0-9)+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0
-9]*)$”
8、非正浮點數(shù):”^((-\d+\.\d+)?)|(0+(\.0+)?))$”
9、負浮點數(shù):”^(-((正浮點數(shù)正則式)))$”
10、英文字符串:”^[A-Za-z]+$”
11、英文大寫串:”^[A-Z]+$”
12、英文小寫串:”^[a-z]+$”
13、英文字符數(shù)字串:”^[A-Za-z0-9]+$”
14、英數(shù)字加下劃線串:”^\w+$”
15、E-mail地址:”^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$”
16、URL:”^[a-zA-Z]+://(\w+(-\w+)*)(\.(\w+(-\w+)*))*(\?\s*)?$”
JS 端
intege:"^-?[1-9]\\d*$", //整數(shù)
intege1:"^[1-9]\\d*$", //正整數(shù)
intege2:"^-[1-9]\\d*$", //負整數(shù)
num:"^([+-]?)\\d*\\.?\\d+$", //數(shù)字
num1:"^[1-9]\\d*|0$", //正數(shù)(正整數(shù) + 0)
num2:"^-[1-9]\\d*|0$", //負數(shù)(負整數(shù) + 0)
decmal:"^([+-]?)\\d*\\.\\d+$", //浮點數(shù)
decmal1:"^[1-9]\\d*.\\d*|0.\\d*[1-9]\\d*$", //正浮點數(shù)
decmal2:"^-([1-9]\\d*.\\d*|0.\\d*[1-9]\\d*)$", //負浮點數(shù)
decmal3:"^-?([1-9]\\d*.\\d*|0.\\d*[1-9]\\d*|0?.0+|0)$", //浮點數(shù)
decmal4:"^[1-9]\\d*.\\d*|0.\\d*[1-9]\\d*|0?.0+|0$", //非負浮點數(shù)(正浮點數(shù) + 0
)
decmal5:"^(-([1-9]\\d*.\\d*|0.\\d*[1-9]\\d*))|0?.0+|0$", //非正浮點數(shù)(負浮點數(shù)
+ 0)
email:"^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-
9]+$", //郵件
color:"^[a-fA-F0-9]{6}$", //顏色
url:"^http[s]?:\\/\\/([\\w-]+\\.)+[\\w-]+([\\w-./?%&=]*)?$", //url
chinese:"^[\\u4E00-\\u9FA5\\uF900-\\uFA2D]+$", //
僅中文
ascii:"^[\\x00-\\xFF]+$", //僅ACSII字符
zipcode:"^\\d{6}$", //郵編
mobile:"^(13[0-9]{9}|15[012356789][0-9]{8}|18[0256789][0-9]{8}|147[0-9]{8}$)",
//手機
ip4:"^(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|
[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1
-9]?\\d)$", //ip地址
notempty:"^\\S+$", //非空
picture:"(.*)\\.(jpg|bmp|gif|ico|pcx|jpeg|tif|png|raw|tga)$", //圖片
rar:"(.*)\\.(rar|zip|7zip|tgz)$",
//壓縮文件
date:"^\\d{4}(\\-|\\/|\.)\\d{1,2}\\1\\d{1,2}$", //
日期
qq:"^[1-9]*[1-9][0-9]*$", //QQ號碼
tel:"^(([0\\+]\\d{2,3}-)?(0\\d{2,3})-)?(\\d{7,8})(-(\\d{3,}))?$", //電話號碼
的函數(shù)(包括驗證國內(nèi)區(qū)號,國際區(qū)號,分機號)
username:"^\\w+$", //用來用戶注冊。匹
配由數(shù)字、26個英文字母或者下劃線組成的字符串
letter:"^[A-Za-z]+$", //字母
letter_u:"^[A-Z]+$", //大寫字母
letter_l:"^[a-z]+$", //小寫字母
idcard:"^[1-9]([0-9]{14}|[0-9]{17})$" //身份證
更多信息請查看IT技術(shù)專欄