首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

用户名跟密码验证

2012-07-01 
用户名和密码验证script typetext/javascriptfunction isValidate(form){//取得用户登录信息username

用户名和密码验证
<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)"

热点排行