完整的js正则表达式:
//强:字母+数字+特殊字符
^(?![a-zA-z]+$)(?!\d+$)(?![!@#$%^&*]+$)(?![a-zA-z\d]+$)(?![a-zA-z!@#$%^&*]+$)(?![\d!@#$%^&*]+$)[a-zA-Z\d!@#$%^&*]+$//中:字母+数字,字母+特殊字符,数字+特殊字符
^(?![a-zA-z]+$)(?!\d+$)(?![!@#$%^&*]+$)[a-zA-Z\d!@#$%^&*]+$
//弱:纯数字,纯字母,纯特殊字符^(?:\d+|[a-zA-Z]+|[!@#$%^&*]+)$
//校验是否全由数字组成function isDigit(s){var patrn=/^[0-9]{1,20}$/if (!patrn.exec(s)) return falsereturn true
}//校验登录名:只能输入5-20个以字母开头、可带数字、“_”、“.”的字串function isRegisterUserName(s){var patrn=/^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){4,19}$/if (!patrn.exec(s)) return falsereturn true}function isRegisterUserName(s){var patrn=/^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){4,19}$/if (!patrn.exec(s)) return falsereturn true}
//校验用户姓名:只能输入1-30个以字母开头的字串Javascript代码function isTrueName(s){var patrn=/^[a-zA-Z]{1,30}$/if (!patrn.exec(s)) return falsereturn true}}}//校验密码:只能输入6-20个字母、数字、下划线
function isPasswd(s){var patrn=/^(\w){6,20}$/if (!patrn.exec(s)) return falsereturn true}//校验普通电话、传真号码:可以“+”开头,除数字外,可含有“-”
function isTel(s){//var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?(\d){1,12})+$/var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/if (!patrn.exec(s)) return falsereturn true}//校验手机号码:必须以数字开头,除数字外,可含有“-”
function isMobil(s){var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/if (!patrn.exec(s)) return falsereturn true}//校验邮政编码
function isPostalCode(s){//var patrn=/^[a-zA-Z0-9]{3,12}$/var patrn=/^[a-zA-Z0-9 ]{3,12}$/if (!patrn.exec(s)) return falsereturn true}//校验搜索关键字
function isSearch(s){var patrn=/^[^`~!@#$%^&*()+=|\\\][\]\{\}:'\,.<>/?]{1}[^`~!@$%^&()+=|\\\][\]\{\}:'\,.<>?]{0,19}$/if (!patrn.exec(s)) return falsereturn true}function isIP(s) //by zergling{var patrn=/^[0-9.]{1,20}$/if (!patrn.exec(s)) return falsereturn true} 1楼的貌似没看清楚问题,要求是必须含字母和数字,不是必须是字母或数字。functioncheck(){varstr=‘要检查的字符串’varreg=newRegExp(/[A-Za-z].*[0-9]|[0-9].*[A-Za-z]/)if(reg.test(str)){returntrue}else{returnfalse}}题主你好,
正则及测试截图如下:
文字版:
^(?=(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[\\W_])|(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])|(?=.*[0-9])(?=.*[a-z])(?=.*[\\W_])|(?=.*[0-9])(?=.*[A-Z])(?=.*[\\W_])|(?=.*[a-z])(?=.*[A-Z])(?=.*[\\W_]))[a-zA-Z0-9\\W_]{8,16}$
-----
另外我在网上看了一下,还有另一种写法:
^(?![A-Za-z]+$)(?![A-Z\d]+$)(?![A-Z\W]+$)(?![a-z\d]+$)(?![a-z\W]+$)(?![\d\W]+$)\S{8,16}$
-----
总结: 这两种方法原理其实是一样的, 第一种情况是匹配所有满足条件的组合, 第二种情况是排除所有不满足条件的组合 //这里的条件指的是字符串必须含有三种以上类型的字符
=====
希望可以帮到题主, 欢迎追问.