js验证用户名实例

< script  language ="javascript"   type ="text/javascript" >
       
function  checkname()
       {
          
var  str = document.form1.username.value;
          
if (str.length < 6 || str.length > 10 )
          {
            document.getElementById(
" err " ).innerHTML = " <font>用户名长度错误!</font> " ;
            document.form1.username.focus();
          }
          
else
          {
             document.getElementById(
" err " ).innerHTML = "" ;
          }
       }
</ script >

 

 
1  < form  id ="form1"  name ="form1"  method ="post"  action ="" >
2     < label >
3    用户名:
4     < input  type ="text"  name ="username"   onblur ="checkname()" />< span  id ="err" ></ span >
5     </ label >
6  </ form >

 

你可能感兴趣的:(js)