1 User name Regular
//用户名正则,4到16位(字母,数字,下划线,减号)var uPattern = /^[a-zA-Z0-9_-]{4,16}$/;//输出 trueconsole.log(uPattern.test("iFat3"));
2 Password Strength Regular
Password strength Regular, minimum 6 bits, including at least 1 uppercase letters, 1 lowercase letters, 1 digits, 1 special characters var ppattern = /^. * (? =. {6,}) (? =. *\d) (? =. *[a-z]) (? =. *[a-z]) (? =. *[[email protected]#$%^&*?]) . *$/; //output trueconsole. Log ( "= =" +ppattern. Test ( "ifat3#"))
3 integer Regular
Positive integer Regularvar Pospattern=/^\d+$/;Negative integer Regularvar Negpattern=/^-\d+$/;Integer regularvar Intpattern=/^-? \d+$/; //output trueconsole. Log (pospattern. Test ( ")" ; //output trueconsole. Log (negpattern. Test ( " -42")) ; //output trueconsole. Log (intpattern. Test ( " -42"))
4 Number Regular
Can be an integer or a floating-point number
Positive positivevar Pospattern=/^\d*\.? \d+$/;Negative number Regularvar Negpattern=/^-\d*\.? \d+$/;Number Regularvar numpattern = /^ -?\d*\.? \d+$/; console. log (pospattern. Test ( "42.2")) ; console. log (negpattern. Test ( " -42.2")) ; console. log (numpattern. Test ( " -42.2"))
5 Email Regular
//Email正则var ePattern = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;//输出 trueconsole.log(ePattern.test("[email protected]"));
6 Mobile phone Number regular
//手机号正则var mPattern = /^[1][3][0-9]{9}$/;//输出 trueconsole.log(mPattern.test("13900000000"));
7 Regular ID number
Social Security Number (18-bit) regularvar CP=/^[1-9]\d{5} (18| 19| ( [23]\d)) \d{2} ((0[1-9]) | ( 10| 11| 12 10| 20| 30| 31) \d{3}[0-9xx]$/; //output trueconsole. Log (cp. Test (
8 URL Regular
//URL正则var urlP= /^((https?|ftp|file):\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/;//输出 trueconsole.log(urlP.test("http://42du.cn"));
9 IPV4 Address Regular
/ /ipv4 address regular var IpP = / ^ (? : (? : 25[0-5]| 2[0-4][0-9]|[ 01]? [0-9] [0-9]?) \.) {3} (? :25[0-5]| 2[0-4][0-9]|[ 01]? [0-9] [0-9]?) $/; //output trueconsole. Log (ipp. Test ( "115.28.47.26"))
106 Binary Color Regular
//RGB Hex颜色正则var cPattern = /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/;//输出 trueconsole.log(cPattern.test("#b8b8b8"));
Regular for the 11th period
Date regular, simple judgment, no month and date judgmentvar dP1=/^\D{4} (\-) \d{1,2}\1\d{1,2}$/;Output trueConsole.LogDP1.Test"2017-05-11"));Output trueConsole.LogDP1.Test"2017-15-11"));Date regularization, complex judgmentvar dP2=/^(?:(?!0000) [0-9]{4}-(?:(?: 0[1-9]|1[0-2])-(?: 0[1-9]|1[0-9]|2[0-8]) | (?: 0[13-9]|1[0-2])-(?: 29|30)| (?: 0[13578]|1[02])-31)| (?:[0-9] {2} (?: 0[48]| [2468] [048]| [13579] [26]) | (?: 0[48]| [2468] [048]| [13579] [26])00)-02-29)$/; //output trueconsole. Log (dp2. Test ( "2017-02-11")) ; //output falseconsole. Log (dp2. Test ( "2017-15-11")) ; //output falseconsole. Log (dp2. Test ( "2017-02-29"))
QQ Number Regular
//QQ号正则,5至11位var qqPattern = /^[1-9][0-9]{4,10}$/;//输出 trueconsole.log(qqPattern.test("65974040"));
Regular number 13th
//号正则,6至20位,以字母开头,字母,数字,减号,下划线var wxPattern = /^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/;//输出 trueconsole.log(wxPattern.test("RuilongMao"));
14 Car Grade Regular
//车牌号正则var cPattern = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$/;//输出 trueconsole.log(cPattern.test("京K39006"));
15 includes Zhong Wenjing
//包含中文正则var cnPattern = /[\u4E00-\u9FA5]/;//输出 trueconsole.log(cnPattern.test("42度"));
来源地址:http://www.cnblogs.com/ifat3/archive/2017/05/15/6855141.html
15 Common regular Expressions in "turn" JS