javascript正则表达式验证密码(必须含数字字符特殊符号,长度4-16位之间)
- var newpwd = $("#newpassword").val();
- //var pattern = "([A-Za-z]|[0-9]|-|_){4,16}";
- //var reg = new RegExp(pattern,"g");
- var reg = /^(?=.*[a-zA-Z])(?=.*\d)(?=.*[~!@#$%^&*()_+`\-={}:";'<>?,.\/]).{4,16}$/;
- var flag = reg.test(newpwd);
- if(flag == false){
- alert("新密码必须由 4-16位字母、数字、特殊符号线组成.");
- return false;
- }