js常用的正则表达式收集

正则表达式在线校验地址:https://tool.oschina.net/regex/

1、邮箱正则

const emailReg = /^\w+((.\w+)|(-\w+))@[A-Za-z0-9]+((.|-)[A-Za-z0-9]+).[A-Za-z0-9]+$/

2、手机号正则

const phoneReg = /^[1][3,4,5,7,8][0-9]{9}$/

3、IPv4地址正则

const ipReg = /^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$/

4、18位身份证号正则

const idReg = /^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/

5、域名正则

const domainReg = /^(?=^.{3,255}$)[a-zA-Z0-9*]?[-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9*][-a-zA-Z0-9]{0,62})+[(com)|(cn)|(xin)|(net)|(top)|(xyz)|(wang)|(shop)|(site)|(club)|(cc)|(fun)|(online)|(biz)|(red)|(link)|(ltd)|(mobi)|(info)|(org)|(name)|(vip)|(pro)|(work)|(tv)|(co)|(kim)|(group)|(tech)|(store)|(ren)|(pub)|(ink)|(live)|(wiki)|(design)]$/

6、网址URL正则

const idReg = /[a-zA-z]+:\/\/[^\s]*/

其他正则推荐参考:
https://blog.csdn.net/ZYC88888/article/details/98479629

正则表达式的贪婪匹配与非贪婪匹配:
https://www.jianshu.com/p/974dee8953e6

正则表达式(小括号)、[中括号]、{大括号}的区别小结:
https://www.cnblogs.com/hjbky/p/9512022.html

你可能感兴趣的:(js)