js 常用正则表达式

前端之家收集整理的这篇文章主要介绍了js 常用正则表达式前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<div class="cnblogs_code">
<div class="cnblogs_code">

1用户名正则
用户名正则,4到16位(字母,数字,下划线,减号)
 uPattern = /^[a-zA-Z0-9_-]{4,16}$/输出 true
console.log(uPattern.test("iFat3"2包括至少1个大写字母,1个小写字母,1个数字,1个特殊字符
 pPattern = /^.*(?=.{6,})(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*? ]).*$/输出 true
console.log("=="+pPattern.test("iFat3#"3整数正则
整数正则
 posPattern = /^\d+$/整数正则
 negPattern = /^-\d+$/整数正则
 intPattern = /^-?\d+$/输出 true
console.log(posPattern.test("42"输出 true
console.log(negPattern.test("-42"输出 true
console.log(intPattern.test("-42"4<span style="color: #008000">//<span style="color: #008000">正数正则
<span style="color: #0000ff">var
posPattern = /^\d.?\d+$/<span style="color: #000000">;
<span style="color: #008000">//
<span style="color: #008000">负数正则

<span style="color: #0000ff">var
negPattern = /^-\d.?\d+$/<span style="color: #000000">;
<span style="color: #008000">//
<span style="color: #008000">数字正则

<span style="color: #0000ff">var
numPattern = /^-?\d.?\d+$/<span style="color: #000000">;
console.log(posPattern.test(
"42.2"<span style="color: #000000">));
console.log(negPattern.test(
"-42.2"<span style="color: #000000">));
console.log(numPattern.test(
"-42.2"<span style="color: #000000">));
5<span style="color: #000000"> Email正则
<span style="color: #008000">//
<span style="color: #008000">Email正则

<span style="color: #0000ff">var
ePattern = /^([A-Za-z0-9-.])+\@([A-Za-z0-9-.])+.([A-Za-z]{2,4})$/<span style="color: #000000">;
<span style="color: #008000">//
<span style="color: #008000">输出 true

console.log(ePattern.test("65974040@qq.com"<span style="color: #000000">));
6<span style="color: #000000"> 手机号码正则
<span style="color: #008000">//
<span style="color: #008000">手机号正则

<span style="color: #0000ff">var mPattern = /^[1][3][0-9]{9}$/<span style="color: #000000">;
<span style="color: #008000">//<span style="color: #008000">输出 true
console.log(mPattern.test("13900000000"<span style="color: #000000">));
7<span style="color: #000000"> 身份证号正则
<span style="color: #008000">//<span style="color: #008000">身份证号(18位)正则
<span style="color: #0000ff">var cP = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/<span style="color: #000000">;
<span style="color: #008000">//<span style="color: #008000">输出 true
console.log(cP.test("11010519880605371X"<span style="color: #000000">));
8<span style="color: #000000"> URL正则
<span style="color: #008000">//<span style="color: #008000">URL正则
<span style="color: #0000ff">var urlP= /^((https?|ftp|file):\/\/)?([\da-z.-]+).([a-z.]{2,6})([\/\w .-]
)*\/?$/<span style="color: #000000">;
<span style="color: #008000">//<span style="color: #008000">输出 true
console.log(urlP.test("http://42du.cn"<span style="color: #000000">));
9<span style="color: #000000"> IPv4地址正则
<span style="color: #008000">//<span style="color: #008000">ipv4地址正则
<span style="color: #0000ff">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]?)$/<span style="color: #000000">;
<span style="color: #008000">//<span style="color: #008000">输出 true
console.log(ipP.test("115.28.47.26"<span style="color: #000000">));
10<span style="color: #000000"> 十六进制颜色正则
<span style="color: #008000">//<span style="color: #008000">RGB Hex颜色正则
<span style="color: #0000ff">var cPattern = /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/<span style="color: #000000">;
<span style="color: #008000">//<span style="color: #008000">输出 true
console.log(cPattern.test("#b8b8b8"<span style="color: #000000">));
11<span style="color: #000000"> 日期正则
<span style="color: #008000">//<span style="color: #008000">日期正则,简单判定,未做月份及日期的判定
<span style="color: #0000ff">var dP1 = /^\d{4}(-)\d{1,2}\1\d{1,2}$/<span style="color: #000000">;
<span style="color: #008000">//<span style="color: #008000">输出 true
console.log(dP1.test("2017-05-11"<span style="color: #000000">));
<span style="color: #008000">//<span style="color: #008000">输出 true
console.log(dP1.test("2017-15-11"<span style="color: #000000">));
<span style="color: #008000">//<span style="color: #008000">日期正则,复杂判定
<span style="color: #0000ff">var 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)$/<span style="color: #000000">;
<span style="color: #008000">//<span style="color: #008000">输出 true
console.log(dP2.test("2017-02-11"<span style="color: #000000">));
<span style="color: #008000">//<span style="color: #008000">输出 false
console.log(dP2.test("2017-15-11"<span style="color: #000000">));
<span style="color: #008000">//<span style="color: #008000">输出 false
console.log(dP2.test("2017-02-29"<span style="color: #000000">));
12<span style="color: #000000"> QQ号码正则
<span style="color: #008000">//<span style="color: #008000">QQ号正则,5至11位
<span style="color: #0000ff">var qqPattern = /^[1-9][0-9]{4,10}$/<span style="color: #000000">;
<span style="color: #008000">//<span style="color: #008000">输出 true
console.log(qqPattern.test("65974040"<span style="color: #000000">));
13<span style="color: #000000"> 微信号正则
<span style="color: #008000">//<span style="color: #008000">微信号正则,6至20位,以字母开头,字母,数字,减号,下划线
<span style="color: #0000ff">var wxPattern = /^a-zA-Z+$/<span style="color: #000000">;
<span style="color: #008000">//<span style="color: #008000">输出 true
console.log(wxPattern.test("RuilongMao"<span style="color: #000000">));
14<span style="color: #000000"> 车牌号正则
<span style="color: #008000">//<span style="color: #008000">车牌号正则
<span style="color: #0000ff">var cPattern = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$/<span style="color: #000000">;
<span style="color: #008000">//<span style="color: #008000">输出 true
console.log(cPattern.test("京K39006"<span style="color: #000000">));
15<span style="color: #000000"> 包含中文正则
<span style="color: #008000">//<span style="color: #008000">包含中文正则
<span style="color: #0000ff">var cnPattern = /[\u4E00-\u9FA5]/<span style="color: #000000">;
<span style="color: #008000">//<span style="color: #008000">输出 true
console.log(cnPattern.test("42度"));

<pre class="best-text mb-10">

Regex_Phones: /^[0-9],$/,
Regex_Ident: /^([a-zA-Z0-9]){1,50}$/,英文标点和特殊符号(渠道标识)
Regex_IdentName: /^([\u2E80-\u9FFF]|[a-zA-Z0-9]){1,中文、英文、数字且不能包含英文标点和特殊符号(渠道名称)
Regex_MondyNum: /^\d+(\.\d{1,2})?$/,
Regex_MondyCh: /^[\u4e00-\u9fa5]+$/,中文
Regex_PhoneNum: /(^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$)|(^0{0,1}1[3|4|5|6|7|8|9][0-9]{9}$)/,
Regex_ZNum: /^[1-9]\d*$/ 
Regex_Name: /^[a-zA-Z][a-zA-Z0-9_@]{0,30}$/,用户名
Regex_NickName: /^[\u4E00-\u9FA5A-Za-z0-9_\-]+$/,中文/英文/数字, (昵称、组名、朋友备注名、内容名称、书名、页名) 
Regex_Passport: /^1[45][0-9]{7}$|G[0-9]{8}$|P\.[0-9]{7}$|S[0-9]{7,8}$|D[0-9]{7,8}$/,
Regex_BizLience: /^([0-9a-zA-Z]{18}$|\d{15}$)/,
Regex_isExitZh:/[\u4E00-\u9FA5\uF900-\uFA2D]/,中文
Regex_price:/^\d+(\.\d{1,2})?$/ 
Regex_EnghlishNum:/^(?=.*\d)(?=.*[a-z])[a-zA-Z\d]{6,20}$/ 
Regex_Phone: /^0?(13[0-9]|15[012356789]|18[0-9]|14[57])[0-9]{8}$/,
Regex_Mobile: /^0?(13[0-9]|15[012356789]|18[0-9]|14[57])[0-9]{8}$/,
Regex_Card: /\\d{14}[[0-9],0-9xX]/,
Regex_Email: /^[a-zA-Z0-9]+([._\\-]*[a-zA-Z0-9])*@([a-zA-Z0-9]+[-a-zA-Z0-9]*[a-zA-Z0-9]+.){1,63}[a-zA-Z0-9]+$/,
Regex_RealName: /^[a-zA-Z\u4e00-\u9fa5]{0,}$/,名称、组标签
Regex_text: /^[\u4e00-\u9fa5]{0,^[\d]+.+。Regex_NumFloat^(\-|\+)?\d+(\.\d+)?$
原文链接:https://www.f2er.com/regex/73941.html

猜你在找的正则表达式相关文章