如aaaaaa或者abcdefgh这样都不通过,但是aabbcccdddd可以。如果js不能实现,用什么方法可以实现?
function checkPassword(pwd) { // 长度为6到18个字符 var reg = /^.{6,16}$/; if (!reg.test(pwd)) { return false; } // 全部重复 var repeat = true; // 连续字符 var series = true; var len = pwd.length; var first = pwd.charAt(0); for (var i = 1; i < len; i++) { repeat = repeat && pwd.charAt(i) == first; series = series && pwd.charCodeAt(i) == pwd.charCodeAt(i - 1) + 1; } return !(repeat || series); }