6-5.htm

来自「JScript网页特效,包含很多的实现网页特效的方法.」· HTM 代码 · 共 69 行

HTM
69
字号
<html>
<head>
<title>§6.5 检查输入密码的合法性</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language=javascript>
<!--//Begin code
function contain(str, charset)
{
  var i;

  for(i=0;i<charset.length;i++)
    if(str.indexOf(charset.charAt(i))>=0)
       return true;

  return false;
}

function check()
{               
  if((document.test.username.value==null)||(document.test.username.value.length==0))
  {   
    alert("用户名为空,请重新输入");
    document.test.username.focus();
    return false;
  }
  if(contain(document.test.username.value,' <>{}\\'))
  {
     alert("用户名中含有非法字符<>{}\\或空格!");
     document.test.username.focus();
     return false;
  }

  if((document.test.passwd.value==null)||(document.test.passwd.value.length==0))
  {   
    alert("密码为空,请重新输入");
    document.test.passwd.focus();
    return false;
  }
  if(contain(document.test.passwd.value,' <>{}\\'))
  {
    alert("密码中含有非法字符<>{}\\或空格!");
    document.test.passwd.focus();
    return false;
  }
  return true;
}
//End code
-->
</script>
</head>

<body bgcolor="#FFFFFF">
<form name="test" method="post" action="test" onsubmit="return check()">

  <p>密码验证 </p>
  <p>用户名: 
    <input type="text" name="username" value="" >
  </p>
  <p>密<font color="#FFFFFF">--</font>码: 
    <input type="password" name="passwd" value="" >
  </p>
  <p> 
    <input type="submit" name="Submit" value="确定">
  </p>
  <p>输入&lt;&gt;{}\\或空格等非法字符试试。</p>
</form>
</body>
</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?