js 常用正则表达式

发布时间:2019-10-29 发布网站:大佬教程
大佬教程收集整理的这篇文章主要介绍了js 常用正则表达式大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

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

1
 uPattern = /^[a-zA-Z0-9_-]{4,16}$/
console.log(uPattern.test("iFat3"2
 pPattern = /^.*(?=.{6,})(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*? ]).*$/
console.log("=="+pPattern.test("iFat3#"3
 posPattern = /^\d+$/
 negPattern = /^-\d+$/
 intPattern = /^-?\d+$/
console.log(posPattern.test("42"
console.log(negPattern.test("-42"
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+)?$

大佬总结

以上是大佬教程为你收集整理的js 常用正则表达式全部内容,希望文章能够帮你解决js 常用正则表达式所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ群:277859234,请注明来意。
猜你在找的正则表达式相关文章
全站导航更多
最新正则表达式教程
热门正则表达式教程