(?![^a-zA-Z]+$)(?!\D+$)(?![a-zA-Z0-9]+$).{8,}$
使用示例:
function valPasswordFormatNew(){ var result = true; var newPsd = jQuery("#newPsd").val(); if(newPsd !=""){ result = (/(?![^a-zA-Z]+$)(?!\D+$)(?![a-zA-Z0-9]+$).{8,}$/.test(newPsd)); if(newPsd.length<8){ result = "<@cfw.m code="auth.emsUser.psw.size.error"/>"; } else if(!result){ result = "<@cfw.m code="auth.emsUser.psw.vilate"/>"; } } if(newPsd != "" && result){ jQuery("#confirmPassword").attr("data-validation-engine", "validate[required,funcCall[confirmPsd]]"); } return result; }
或者:
function valPasswordFormat(){ var result = true; var password = jQuery("#password").val(); //校验数字字母特殊字符同时存在,长度不小于8位 if(password.length < 8){ return "密码长度不能小于8位!"; } //判断字符串是否为数字和字母 var regex = /(?![^a-zA-Z]+$)(?!\D+$)(?![a-zA-Z0-9]+$).{8,}$/; if (!regex.test(password)){ return "密码必须由数字、字母和特殊字符组成,且长度不小于8位!"; } return true; }