(1)去除数字
实例:var str = ‘kkf1235d2‘;
var re = /[0-9]/g;
str = str.replace(re, ‘‘);
(2)去除大写字母
实例:var str = ‘KKkf123DD5d2‘;
var re = /[A-Z]/g;
str = str.replace(re, ‘‘);
(3)匹配QQ号码
var re = /^[1-9]\d{4,11}&/;\
(4)匹配邮件
var re = /^\[email protected][a-z0-9]+(\.[a-z]+){1,3}$/
(5)去掉头尾空格
var re = /^\s|\s$/g;
return str = str.replace(re,‘‘);
(6)匹配电话号码
var re = /^((\d{3,4}-)?\d{7,8})$|^(1\d{2,10})$/;
(7)验证密码强度
var str = ‘AAAaaa1111‘;
var re1 = /\d/g;
var re2 = /[a-z]/g;
var re3 = /[A-Z]/g;
if( re1.test(str) && re2.test(str) && re3.test(str) ){
alert(‘困难‘);
}
else if((re1.test(str) && re2.test(str)) || (re1.test(str) && re3.test(str)) || (re2.test(str) && re3.test(str)) ){
alert(‘普通‘);
}
else if(re1.test(str) || re2.test(str) || re3.test(str)){
alert(‘简单‘);
(8)匹配中文
var re = [\u4e00-\u9fa5];
(9)匹配网址
re = [a-zA-z]+://[^\s]*
(10)匹配身份证
re = [1-9]\d{14}|[1-9]\d{17}|[1-9]\d{16}x
(11)匹配邮编
re =[1-9]\d{5}