| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 8313 人关注过本帖, 1 人收藏
标题:求判断两次密码输入是否一致代码
只看楼主 加入收藏
lyg540612
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2008-8-12
收藏(1)
 问题点数:0 回复次数:7 
求判断两次密码输入是否一致代码
我的代码如下
<script type="text/javascript">
function checkform(fName,obj,minl,maxl,hideCode)
{
    switch(fName)
    {
        case "email"://验证电子邮件
           return(checkEmail(obj,minl,maxl,hideCode));
        break;

        case "name"://验证用户名
            return(checkName(obj,minl,maxl,hideCode));
        break;
        case "password"://验证密码
            return(checkpassword(obj,minl,maxl,hideCode));
        break;
        case "QQ"://验证QQ
            return(checkQQ(obj,minl,maxl,hideCode));
        break;
        case "textlength"://限制字数
            return(checkCodeLength(obj,minl,maxl,hideCode));
        break;
        default:
        alert("程序引用错误,需要的参数只能为:\n1.")
        return;
        break;
    }
}
function checkName(obj,Minl,Maxl,hideCode)
{
    //验证用户名程序,限制只能输入英文或数字
    var objvalue=obj.value;
    if(objvalue.length<Minl||objvalue.length>Maxl)
    {
        alert("用户名长度限于"+Minl+"个和"+Maxl+"个字符之间,请重新输入");
        obj.focus();
        return false;
    }
    var reg=/^\w+$/
    if(!reg.test(objvalue))
    {
        alert("用户名只允许包含数字,英文或下划线");
        obj.focus();
        return false;
    }
}
function checkpassword(obj,Minl,Maxl,hideCode)
{
    //验证用户名程序,限制只能输入英文或数字
    var objvalue=obj.value;
    if(objvalue.length<Minl||objvalue.length>Maxl)
    {
        alert("密码长度限于"+Minl+"个和"+Maxl+"个字符之间,请重新输入");
        obj.focus();
        return false;
    }
}
function checkEmail(obj,Minl,Maxl,hideCode)
{
    //验证EMAIL程序
    var objvalue=obj.value;
    if(objvalue.length<Minl||objvalue.length>Maxl)
    {
        alert("对不起,电子邮件字符长度不应该小于"+Minl+"或不应该长于"+Maxl+"个字符");
        obj.focus();
        return false;
    }
    var reg=/^\w+@\w+.(\w+.\w+|\w+)$/;
    if(!reg.test(objvalue))
    {
        alert("请正确输入电子邮件地址");
        obj.focus();
        return false;
    }
}
function checkCodeLength(obj,Minl,Maxl,hideCode)
{
    //验证字数程序
    var valueLength=obj.value.length;
    if(valueLength<Minl||valueLength>Maxl)
    {
        alert("对不起,您输入的长度不符合要求,不应该少于"+Minl+"个字符或多于"+Maxl+"个字符");
        obj.focus();
        return false;
    }
}

function checkQQ(obj,Minl,Maxl,hideCode)
{
    //验证QQ程序
    var objvalue=obj.value;
    var reg=/[1-9^0]\d{5,10}/
    if(!reg.test(objvalue))
        {
            alert("QQ必须为5-10位数字,且第一个数字不能为0");
            return false;
        }
}
//调用程序
function thisForm()
{
var iptName=document.getElementById("name");
var iptpassword=document.getElementById("password");
var iptpassword2=document.getElementById("password2"); //password2为确认密码
var iptEmail=document.getElementById("Email");
var iptQQ=document.getElementById("QQ");
if(checkform("name",iptName,6,16,""))
    {
        return false;
    }
if(checkform("password",iptName,4,10,""))
    {
        return false;
    }
if(checkform("email",iptEmail,10,30,""))
    {
        return false;
    }    
if(checkform("QQ",iptQQ,5,10,""))
    {
        return false;
    }    
}
</script>
搜索更多相关主题的帖子: 密码 代码 判断 输入 
2008-10-01 13:15
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:0 
function checkform(fName,obj,minl,maxl,hideCode)
{
    switch(fName)
    {
        case "email"://验证电子邮件
           return(checkEmail(obj,minl,maxl,hideCode));
        break;

        case "name"://验证用户名
            return(checkName(obj,minl,maxl,hideCode));
        break;
        case "password"://验证密码
            return(checkpassword(obj,minl,maxl,hideCode));
        break;
        case "QQ"://验证QQ
            return(checkQQ(obj,minl,maxl,hideCode));
        break;
        case "textlength"://限制字数
            return(checkCodeLength(obj,minl,maxl,hideCode));
        break;
        default:
        alert("程序引用错误,需要的参数只能为:\n1.")
        return;
        break;
    }
}
function checkName(obj,Minl,Maxl,hideCode)
{
    //验证用户名程序,限制只能输入英文或数字
    var objvalue=obj.value;
    if(objvalue.length<Minl||objvalue.length>Maxl)
    {
        alert("用户名长度限于"+Minl+"个和"+Maxl+"个字符之间,请重新输入");
        obj.focus();
        return false;
    }
    var reg=/^\w+$/
    if(!reg.test(objvalue))
    {
        alert("用户名只允许包含数字,英文或下划线");
        obj.focus();
        return false;
    }
}
function checkpassword(obj,Minl,Maxl,hideCode)
{
    //验证用户名程序,限制只能输入英文或数字
    var objvalue=obj.value;
    var iptpassword=document.getElementById("password");
    var iptpassword2=document.getElementById("password2");
    if(iptpassword.value!=iptpassword2.value)
    {
        alert('两次输入的密码不一致');
    }
    if(objvalue.length<Minl||objvalue.length>Maxl)
    {
        alert("密码长度限于"+Minl+"个和"+Maxl+"个字符之间,请重新输入");
        obj.focus();
        return false;
    }
}
function checkEmail(obj,Minl,Maxl,hideCode)
{
    //验证EMAIL程序
    var objvalue=obj.value;
    if(objvalue.length<Minl||objvalue.length>Maxl)
    {
        alert("对不起,电子邮件字符长度不应该小于"+Minl+"或不应该长于"+Maxl+"个字符");
        obj.focus();
        return false;
    }
    var reg=/^\w+@\w+.(\w+.\w+|\w+)$/;
    if(!reg.test(objvalue))
    {
        alert("请正确输入电子邮件地址");
        obj.focus();
        return false;
    }
}
function checkCodeLength(obj,Minl,Maxl,hideCode)
{
    //验证字数程序
    var valueLength=obj.value.length;
    if(valueLength<Minl||valueLength>Maxl)
    {
        alert("对不起,您输入的长度不符合要求,不应该少于"+Minl+"个字符或多于"+Maxl+"个字符");
        obj.focus();
        return false;
    }
}

function checkQQ(obj,Minl,Maxl,hideCode)
{
    //验证QQ程序
    var objvalue=obj.value;
    var reg=/[1-9^0]\d{5,10}/
    if(!reg.test(objvalue))
        {
            alert("QQ必须为5-10位数字,且第一个数字不能为0");
            return false;
        }
}
//调用程序
function thisForm()
{
var iptName=document.getElementById("name");
var iptpassword=document.getElementById("password");
var iptpassword2=document.getElementById("password2"); //password2为确认密码
var iptEmail=document.getElementById("Email");
var iptQQ=document.getElementById("QQ");
if(checkform("name",iptName,6,16,""))
    {
        return false;
    }
if(checkform("password",iptName,4,10,""))
    {
        return false;
    }
if(checkform("email",iptEmail,10,30,""))
    {
        return false;
    }   
if(checkform("QQ",iptQQ,5,10,""))
    {
        return false;
    }   
}
</script>
2008-10-01 17:35
lyg540612
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2008-8-12
收藏
得分:0 
谢谢您的恢复,两次密码输入错误可是没有反应。
2008-10-01 17:47
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:0 
html代码怎么写的?
2008-10-01 17:50
lyg540612
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2008-8-12
收藏
得分:0 
谢谢您的回复
我想将程序源代码都复制上,可是说是广告,不能发布。不能将程序源代码都复制上
2008-10-01 18:55
lyg540612
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2008-8-12
收藏
得分:0 
<html>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>用户注册</title>
    <style type="text/css">
<!--
.style5 {color: #0000FF}
.style9 {font-size: 9pt; color: #0000FF; }
-->
    </style>
<head>
<title>通用表格验证程序</title>
<script type="text/javascript">
此处就是以上的代码
</head>
   
    <body>
    <FORM ACTION="<%=MM_editAction%>" METHOD="POST" name=Form onSubmit="return thisForm()">
      <TABLE width=767 border=0 align="center" bgcolor="#CCFFFF" style="FONT-SIZE: 12px">
        <TBODY>
          <TR>
            <TD align=right><span class="style9">用户名:</span></TD>
            <TD width="217">
              <div align="left">
                <input name="name" type="text" id="name">
            </div></TD>
            <TD width="343">
              <DIV id=test1Tip style="WIDTH: 250px; font-size: 9pt; font-family: Arial; color: #0000FF;">
                <div align="left">选择一个您喜欢的6到12位用户名</div>
            </DIV></TD>
          </TR>
          <TR>
            <TD align=right><span class="style9">密码:</span></TD>
            <TD><div align="left">
                <input name="password" type="password" id="password">
            </div></TD>
            <TD width="343">
              <DIV id=test1Tip style="WIDTH: 250px; font-size: 9pt; font-family: Arial; color: #0000FF;">
                <div align="left">您的密码</div>
            </DIV></TD>
          </TR>
          <TR>
            <TD align=right><span class="style9">重复密码:</span></TD>
            <TD><div align="left">
                <input name="password2" type="password" id="password2">
            </div></TD>
            <TD width="343">
              <DIV id=test1Tip style="WIDTH: 250px; font-size: 9pt; font-family: Arial; color: #0000FF;">
                <div align="left">重复您的密码</div>
            </DIV></TD>
          </TR>
          <TR>
            <TD align=right><span class="style9">你的性别:</span></TD>
            <TD>
              <div align="left">
                <input name=sex type=radio id=radio value=男 checked>
                <span class="style5"> 男
                <input id=sex1 type=radio value=女 name=sex>
         
          <input type="radio" name="sex" value="保密">
          保密 </span></div></TD>
            <TD>
              <DIV id=sexTip style="WIDTH: 250px; font-size: 9pt; font-family: Arial; color: #0000FF;">
                <div align="left">选择性别</div>
            </DIV></TD>
          </TR>
          <TR>
            <TD align=right><span class="style9">你的年龄:</span></TD>
            <TD><div align="left">
                <input name="age" type="text" id="age">
            </div></TD>
            <TD width="343">
              <DIV id=test1Tip style="WIDTH: 250px; font-size: 9pt; font-family: Arial; color: #0000FF;">
                <div align="left">您的年龄</div>
            </DIV></TD>
          </TR>
          <TR>
            <TD align=right><div align="right" class="style9">出生日期:</div></TD>
            <TD><div align="left">
                <input name="born" type="text" id="born">
            </div></TD>
            <TD>
              <DIV id=csnyTip style="WIDTH: 250px; font-size: 9pt; font-family: Arial; color: #0000FF;">
                <div align="left">日期的有效形式为:1982-09-21</div>
            </DIV></TD>
          </TR>
          <TR>
            <TD align=right><div align="right" class="style9">QQ:</div></TD>
            <TD><div align="left">
                <input name="QQ" type="text" id="QQ">
            </div></TD>
            <TD>
              <DIV id=sfzhTip style="WIDTH: 250px; font-size: 9pt; font-family: Arial; color: #0000FF;">
                <div align="left">由6到10位数字组成的QQ号</div>
            </DIV></TD>
          </TR>
          <TR>
            <TD align=right><span class="style9">电子邮箱:</span></TD>
            <TD><div align="left">
                <input name="email" type="text" id="email">
            </div></TD>
            <TD>
              <DIV id=emailTip style="WIDTH: 250px; font-size: 9pt; font-family: Arial; color: #0000FF;">
                <div align="left">有效的电子邮箱地址</div>
            </DIV></TD>
          </TR>
          <TR>
            <TD align=right><span class="style9">你的学历:</span></TD>
            <TD>
              <div align="left">
                <select name=record id=select>
                  <option selected>-请选择学历-</option>
                  <option value="高中">高中</option>
                  <option value="专科">专科</option>
                  <option value="本科">本科</option>
                  <option value="研究生">研究生</option>
                  <option value="硕士">硕士</option>
                  <option value="博士">博士</option>
                </select>
            </div></TD>
            <TD>
              <DIV id=xueliTip style="WIDTH: 250px; font-size: 9pt; font-family: Arial; color: #0000FF;">
                <div align="left">请选择您的学历</div>
            </DIV></TD>
          </TR>
          <TR>
            <TD align=right><span class="style9">密码问题提示:</span></TD>
            <TD><div align="left">
                <input name="question" type="text" id="question">
            </div></TD>
            <TD>
              <DIV id=shoujiTip style="WIDTH: 250px; font-size: 9pt; font-family: Arial; color: #0000FF;">
                <div align="left">忘记密码找回时用。如:我的名字</div>
            </DIV></TD>
          </TR>
          <TR>
            <TD align=right><span class="style9">密码问题答案:</span></TD>
            <TD>
              <div align="left">
                <input name="answer" type="text" id="answer">
            </div></TD>
            <TD>
              <DIV id=lxdhTip style="WIDTH: 250px; font-size: 9pt; font-family: Arial; color: #0000FF;">
                <div align="left">找回密码。答案如:王杰</div>
            </DIV></TD>
          </TR>
          <TR>
            <TD align=right><span class="style5">MSN</span><span class="style9">:</span></TD>
            <TD><div align="left">
                <input name="msn" type="text" id="msn">
            </div></TD>
            <TD width="343">
              <DIV id=test1Tip style="WIDTH: 250px; font-size: 9pt; font-family: Arial; color: #0000FF;">
                <div align="left">您的MSN帐号</div>
            </DIV></TD>
          </TR>
          <TR>
            <TD align=right><span class="style5"><span class="style9">个人主页:</span></span></TD>
            <TD><div align="left">
                <input name="url" type="text" id="url" value="http://">
            </div></TD>
            <TD width="343">
              <DIV id=test1Tip style="WIDTH: 250px; font-size: 9pt; font-family: Arial; color: #0000FF;">
                <div align="left">您的网页地址</div>
            </DIV></TD>
          </TR>
          <TR>
            <TD align=right vAlign=top><span class="style9">你的描述:</span></TD>
            <TD vAlign=top colSpan=2><div align="left">
                <TEXTAREA name="content" cols=50 rows=10>这个人比较懒,什么也没有留下。</TEXTAREA>
            </div></TD>
          </TR>
          <TR>
            <TD colspan="3" align=right vAlign=top><div align="center">
                <INPUT id=button2 type=submit value=同意注册协议,现在注册 >
                <input type="reset" name="Submit" value="重置">
                <span class="style5"><a href="../index.asp">返回</a></span></div></TD>
          </TR>
        </TBODY>
      </TABLE>
        </form>
    </body>



</html>
2008-10-01 18:58
lyg540612
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2008-8-12
收藏
得分:0 
不知怎么,可以了。谢谢您了!!!可是加上插入记录后,用户名、密码、Email、QQ其中一个有错误就出现:
错误类型:
Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
[Microsoft][ODBC Microsoft Access Driver] 字段 'user.name' 不能是零长度的字符串。
如何实现只出现提示错误,并返回此页面。谢谢了,我是个菜鸟,太笨了!!!
2008-10-01 19:51
lyg540612
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2008-8-12
收藏
得分:0 
如2楼的代码“ alert('两次输入的密码不一致');”在这一行下应该加上如下代码:
 obj.focus();
 return false;
2008-10-02 12:16
快速回复:求判断两次密码输入是否一致代码
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019176 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved