javascript检查密码格式的合法性

qq_33264352 2018-05-04 10:40:43
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<script language="javascript">
<!--
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 SetFocus(){
if(document.Login.UserName.value=="")
document.Login.UserName.focus();
else
document.Login.UserName.select();
}
function CheckForm()
{
if(document.Login.UserName.value=="")
{alert("请输入用户名!");
document.Login.UserNmae.focus();
return false;
}
if(contain(document.Login.UserName.value,'<>{}\\'))
{alert("用户名中含有非法字符<>{}\\或空格");
document.Login.UserNmae.focus();
return false;
}
if(documeny.Login.Password.value=="")
{alert("请输入密码!");
document.Login.Password.focus();
return false;
}
if(contain(document.Login.Password.value,'<>{}\\'))
{alert("密码中含有非法字符<>{}\\或空格");
document.Login.Password.focus();
return false;
}
}
-->
</script>
</head>
<body bgcolor="0099ff">
<form name="Login" action="check.asp" method="post" target="_parent" onSubmit="return CheckForm();">
<table width="100%" border="0" cellspacing="8" cellpadding="0" align="center">
<tr align="center">
<td height="38" colspan="2"><font size="3">用户登录</font></td>
</tr>
<tr>
<td align="right">用户名称:</td>
<td><input name="UserName" type="text" id="UserName4" maxlength="20" onFocus="this.select();"></td>
</tr>
<tr>
<td align="right"><span class="style1">用户密码:</span></td>
<td><input name="Password" type="password" maxlength="20" onFocus="this.select();"></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input name="Submit" type="submit" value="确 认"> 
<input name="reset" type="reset" id="reset" value="清 除"><br>
</div></td>
</tr>
</table>
</form>
</body>
</html>
要求对用户输入的用户名和密码的情况作出判断 提示用户是否输入了用户名、密码 提示用户不要讲一些特殊字符作为密码或用户名

实现上述要求要如何进行修改 这个代码只能检测用户名是否为空
...全文
1104 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_33264352 2018-05-06
  • 打赏
  • 举报
回复
引用 2 楼 jslang 的回复:
代码中三处拼写错误。已标红 function CheckForm() { if (document.Login.UserName.value == "") { alert("请输入用户名!"); document.Login.UserNmae.focus(); return false; } if (contain(document.Login.UserName.value, '<>{}\\')) { alert("用户名中含有非法字符<>{}\\或空格"); document.Login.UserNmae.focus(); return false; } if (documeny.Login.Password.value == "") { alert("请输入密码!"); document.Login.Password.focus(); return false; }
感谢提醒 没想到视频错了
75闪光雷 2018-05-04
  • 打赏
  • 举报
回复
百度一下 js正则表达式 直接用就可以了
风中的少年 2018-05-04
  • 打赏
  • 举报
回复
http://www.jq22.com/jquery-info994 ,看看别人的代码, 也许对你有帮助
天际的海浪 2018-05-04
  • 打赏
  • 举报
回复
代码中三处拼写错误。已标红 function CheckForm() { if (document.Login.UserName.value == "") { alert("请输入用户名!"); document.Login.UserNmae.focus(); return false; } if (contain(document.Login.UserName.value, '<>{}\\')) { alert("用户名中含有非法字符<>{}\\或空格"); document.Login.UserNmae.focus(); return false; } if (documeny.Login.Password.value == "") { alert("请输入密码!"); document.Login.Password.focus(); return false; }

87,997

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧