用户名和密码验证

<script type="text/javascript"> 
  function isValidate(form) 
  { 
  //取得用户登录信息 
  username = form.username.value; 
  userpass = form.userpass.value; 
  
  //判断用户名长度 
  if(!minLength(username,6)) 
  { 
  alert("用户名长度小于6位!"); 
  form.username.focus(); 
  return false; 
  } 
  
  if(!maxLength(username,8)) 
  { 
  alert("用户名长度大于8位!"); 
  form.username.focus(); 
  return false; 
  } 
  
  //判断密码长度 
  if(!minLength(userpass,6)) 
  { 
  alert("密码长度小于6位!"); 
  form.username.focus(); 
  return false; 
  } 
  
  if(!maxLength(userpass,8)) 
  { 
  alert("密码长度大于8位!"); 
  form.username.focus(); 
  return false; 
  } 
  return true; 
  } 
  
  //验证是否满足最小长度 
  function minLength(str,length) 
  { 
  if(str.length>=length) 
  return true; 
  else 
  return false 
  } 
  
  //验证是否满足最小长度 
  function maxLength(str,length) 
  { 
  if(str.length<=length) 
  return true; 
  else 
  return false 
  } 
  </script> 


onsubmit="return isValidate(form1)"
posted @ 2012-04-19 15:06  Java EE  阅读(699)  评论(0编辑  收藏  举报