常用正则表达式(不定时更新)
常用正则表达式
- 手机号(以 1 开头):
/^(?:(?:\+|00)86)?1\d{10}$/
- 手机号(以 13 至19 开头):
/^(?:(?:\+|00)86)?1[3-9]\d{9}$/
- 手机号(以工信部公布的手机号段开头):
/^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[189]))\d{8}$/
- 国内固话号码:
/\d{3}-\d{8}|\d{4}-\d{7}/
- 邮箱号:
/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
- 邮政编码:
/[1-9]\d{5}(?!\d)/
- 身份证号:
/^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|10|11|12)(?:0[1-9]|[1-2]\d|30|31)\d{3}[\dXx]$/
- 银行卡号(公、私账户):
/^[1-9]\d{9,29}$/
- 车牌号:
/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z][A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学警港澳]$/
- QQ 号:
/^[1-9][0-9]{4,10}$/
- 微信号:
/^[a-zA-Z][-_a-zA-Z0-9]{5,19}$/
- 版本号( x.y.z ):
/^\d+(?:\.\d+){2}$/
- 合法账号1(字母开头,5-16位,允许字母数字下划线):
/^[a-zA-Z][a-zA-Z0-9_]{4,15}$/
- 合法账号2(4-16位,允许字母,数字,下划线,减号):
/^[a-zA-Z0-9_-]{4,16}$/
- 强密码1(必须包含大小写字母和数字的组合,不能使用特殊字符,长度在8-10之间):
/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$/
- 强密码2(必须包含字母、数字、特殊字符):
/^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_!@#$%^&* ~()-+=]+$)(?![a-z0-9]+$)(?![a-z\\W_!@#$%^& *~()-+=]+$)(?![0-9\W_!@#$%^&* ~()-+=]+$)[a-zA-Z0-9\\W_!@#$%^&*~()-+=]/
网址:/^(((ht|f)tps?):\/\/)?(^!@#$%^&*?.\s-?\.)+[a-z]{2,6}\/?/
网址带端口号:/^((ht|f)tps?:\/\/)?[\w-]+(\.[\w-]+)+:\d{1,5}\/?$/
- ip-v4:
/\\b(?:(?: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]?)\\b/
- ip-v6:
/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/