这个是我的源码测试能用
<html>
<head>
</head>
<script type="text/javascript" src="./demo.js"></script>
<body>
<div id="content-area">
<div id="reg-title"></div>
<form method="post" id="pp-form" action="do.php" class="pp-form">
<div>
<label for="reg-un">用户名</label>
<b id="count" style="visibility:hidden">0个字符</b>
<input name="reg-un" id="reg-un" tabindex="1">
<span style="display:none;"></span>
</div>
<div>
<label for="reg-pw">密码</label>
<input id="regpw" name="regpw" type="password" tabindex="2" >
<span id="regpwshow" style="display:none">此处不可空白 </span><em>弱</em><em>中</em><em>强</em>
</div>
<div>
<label for="reg-pw">确认密码
</label>
<input id="con-pw" name="con-pw" type="password" tabindex="3" disabled="">
<span id="con-pwshow" name="con-pwshow"> </span>
</div>
</form>
</div>
</body>
<html>
function getlength(str){
return str.replace(/[^\x00-\xff]/g,"xx").length;
}
function findStr(str,n){
var tmp=0;
for(var i=0;i<str.length;i++){
if(str.charAt(i)==n)
tmp++;
}
return tmp;
}
window.onload=function(){
var ainput=document.getElementsByTagName('input');
var oname=ainput[0];
var pwd=ainput[1];
var pwd2=ainput[2];
var aspan=document.getElementsByTagName('span');
var name_span=aspan[0];
var pwd_span=aspan[1];
var pwd2_span=aspan[2];
var count=document.getElementById('count');
var aem=document.getElementsByTagName('em');
var name_length=0;
oname.onfocus=function(){
name_span.style.display="block";
name_span.innerHTML="<i></i>请输入4-16位字符,一个汉字2个字符、下划线的组合。";
}
oname.onkeyup=function(){
count.style.visibility="visible";
name_length=getlength(this.value);
count.innerHTML=name_length+"多少个字符";
if(name_length==0){
count.style.visibility="hidden";
}
}
oname.onblur=function(){
//\w 字母,数字,下划线
//\u4e00-\u9fa5中文字符
//含有非法字符,不能为空,长度超过25个字符
var re=/[^\w\u4e00-\u9fa5]/g;
if(re.test(this.value)){
name_span.innerHTML='含有非法字符';
}else if(this.value==""){
name_span.innerHTML='不能为空';
}else if(name_length>25){
name_span.innerHTML='超出25个了';
}else{
name_span.innerHTML='ok';
}
}
pwd.onfocus=function(){
pwd_span.style.display="block";
pwd_span.innerHTML=""+'6-16个字符不能单独使用字母或者符号';
}
pwd.onkeyup=function(){
//大于5个字符中,大于10个强
if(this.value.length>5){
aem[1].style.color="blue";
pwd2.removeAttribute('disabled');
pwd2_span.innerHTML="请再输入一次";
}else{
aem[1].style.color="black";
aem[0].style.color="purple";
pwd2.setAttribute('disabled','');
pwd2_span.innerHTML="不够";
}
if(this.value.length<10){
aem[2].style.color="red";
}else{
aem[1].style.color="black";
aem[0].style.color="green";
pwd2.setAttribute('disabled','');
pwd2_span.innerHTML="超了";
}
}
pwd.onblur=function(){
var m=findStr(pwd.value,pwd.value[0]);
if(this.value==""){
pwd_span.innerHTML="断码不能为空";
}else if(m==this.value.length){
pwd_span.innerHTML="不能用相同";
}
}
pwd2.onfocus=function(){
}
pwd2.onkeyup=function(){
}
pwd2.onblur=function(){
}
};
//var re=/\w\u4e00-\u9fa5/g;
//用户名