日期:2014-05-16 浏览次数:20518 次
<input id="username" type="text" value="" />
<input id="password" type="password" value="" />
<script>
var psd = document.getElementById('password'),
username = document.getElementById('username').value;
psd.onchange = function(){
var val = this.value;
if(val.length < 6){
alert("密码过短");
}else if(/^([\da-zA-Z])\1+$/.test(val)){
alert("不能为重复字符");
}else if(username.indexOf(val) !== -1){
alert("不能使用跟用户名一样的密码、或者用户名中包含密码");
}else{
var arr = val.split(""),
firstCharcode = val.charCodeAt(0),
ret = false;
for(var i = 0, len = arr.length; i < len; i++){
if(arr[i] !== String.fromCharCode(firstCharcode + i)){
ret = true;
break;
}
}
if(!ret){
alert("不能为连续数字或字符");
}
}
}
</script>