js验证 两次密码是否输入一致 和 密码不能小于八位的方法如何写
解决方案 »
- 请问
- 怎么用正则表达式获取<BODY></BODY>之间的内容
- 急急急急急急急急急急急急急急
- 菜鸟求救..在线等..类似于在线装机的问题....
- 一个正则表达式的问题,一段字符串要同时满足 第一个字为“你”,中间含有一个字“真帅”,字符串长度为9,可以是字符和数字的组合
- 如何判断输入文本框的内容是不是汉字、数字,或只允许文本框输入字母汉字,高手解答哈,偶很菜的
- 急!为什么浏览器不能运行*.class文件了,在线等...
- 请问如何禁止通过查看菜单查看网页源代码
- 微软IE暴露缺陷 5行代码就能使浏览器崩溃
- 如实现页面装载过程中显示进度的程序。
- 帮我看下面这个jquery那里错啦
- iframe自适应高度的问题,正解结贴!
var cuowu="<img src='./image/cuowu.png' alt='错误' width='18' height='18' />";
function checkValue(varInput)
{
var tip = $(varInput.id+"_notice");
//密码验证
if(varInput.id=="password")
{
if(varInput.value==="")
{
tip.innerHTML=cuowu+"<font color='red'>密码不允许为空!</font>";
}
else
{
if(isPass(varInput.value))
{
tip.innerHTML=zhengque;
}
else
{
tip.innerHTML=cuowu+"<font color='red'>您填写的密码格式不正确!</font>";
}
}
}
//确认密码验证
if(varInput.id=="password2")
{
if(varInput.value==="")
{
tip.innerHTML=cuowu+"<font color='red'>确认密码不允许为空!</font>";
ckResult=0;
}
else
{
if(isPass(varInput.value))
{
if(varInput.value==$("password").value)
{
tip.innerHTML=zhengque;
}
else
{
tip.innerHTML=cuowu+"<font color='red'>您两次填写的密码不一致!</font>"; }
}
else
{
tip.innerHTML=cuowu+"<font color='red'>您填写的密码格式不正确!</font>";
}
}
}html代码中table 部分
<tr>
<th>密码:</th>
<td >
<s:password name="password" id="password" maxlength="20" onblur="checkValue(this);" />
<label id="password_notice"></label>
<p>密码可使用英文、下划线、@符号、$符号、数字,总字符数在6 - 20之间。</p>
</td>
</tr>
<tr>
<th>确认密码:</th>
<td >
<s:password name="password2" id="password2" maxlength="20" onblur="checkValue(this);" />
<label id="password2_notice"></label>
<p>再次输入密码,确保密码无误。</p>
</td>
</tr>
function isPass(str)
{
str=trim(str);
var vReg = /^[\w@$]{8,20}$/;
return vReg.test(str);
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<script type="text/javascript">
/**
* author: develop_design_level
* date: 2009-10-30
* @param {Object} id
*/
function $(id){
if (document.getElementById) {
return document.getElementById(id);
}
else {
return document.all.id;
}
}
function checkPwd(){
var oldPwd = $('oldPwdId').value;
var newPwd = $('newPwdId').value;
if(oldPwd.length < 8){
alert('密码1的程度不够8位,请重新输入!');
$('oldPwdId').focus();
$('oldPwdId').select();
return;
}
if(newPwd.length < 8){
alert('密码2的程度不够8位,请重新输入!');
$('oldPwdId').value = '';
$('newPwdId').value = '';
$('oldPwdId').focus();
return;
}
if(oldPwd != newPwd){
alert('输入的两次密码不一致,请重新输入!');
$('oldPwdId').value = '';
$('newPwdId').value = '';
$('oldPwdId').focus();
}else{
alert('---- 密码一致,恭喜!----');
}
}
window.onload = function(){
$('btnId').onclick = checkPwd;
};
</script>
</head>
<body>
<form>
密码1:<input type="password" id="oldPwdId" /><br/>
密码2:<input type="password" id="newPwdId" /><br/>
<input type="button" id="btnId" value=" 提交 "/>
</form>
</body>
</html>