收集常用的正则表达式,欢迎补充。
1.匹配IP地址
function isIP(value){ return /^((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})$/i.test);}
2.匹配URL
- isURL/^((http|https):\/\/(\w+:{0,1}\w*@)?(\S+)|)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/ 3.匹配全汉字
/^[\u4E00-\u9FA3]{1,}$/ 4.匹配身份证号码
- isChina
/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/ 5.匹配手机号码
- isIDCard
/^0?(13[0-9]|15[012356789]|18[0236789]|14[57])[0-9]{8}$/ 6.匹配邮箱
- isPhoneNum
/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/ 7.匹配数字
- isEmail
/^-?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/ 8.匹配日期
- isNum
!/Invalid|NaN/(new Date).toString()); 9.匹配字母和下划线开头,允许n-m字节,允许字母数字下划线
- isDate
,mnvar _n = n-1 _m m;RegExp("^[a-zA-Z_][a-zA-Z0-9_]{"+_n+","_m"}$" 调用方法:
- isAccountValid
var isEmail isEmail($("#input1"val());alertisEmail);//true orfalse
以上的表达式均返回true or false。true为真,false为假。欢迎补充
原文链接:https://www.f2er.com/regex/361233.html