柴好憨好憨 2021-12-16 14:11 采纳率: 16.7%
浏览 36

简单的智能表单,无法获取未定义或 null 引用的属性“toLowerCase”

需要制作一个智能表单,但是一直达不到要求,请问是哪里的代码出了问题?

img

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<script>
<!--
function registerform(){
    if(nameCheck()&&passwordCheck()&&emailCheck())
        return true;
    else
        return false;
}
function nameCheck(nameId){
    var name=document.myform.txtName.value;
    if(name.length!=0){
        for(var i=0;i<name.length;i++){
            var str=nameId.toLowerCase().charAt(i);
            if(!((str>="a"&&str<="z")&&(str>="0"&&str<="9")||str=="_")){
                console.log("会员名输入格式不正确");
                return false;
            }
        }
        return true;
    }
}
function passwordCheck(){
    var password=document.myform.txtPassword.value;
    if(password.length<6){
        console.log("密码必须多于6个字符。\n");
        document.myform.txtPassword.value="";
        document.myform.txtPassword.style.color="red";
        return false;
        }
    return true;
    }

function emailCheck(){
    var email=document.myform.txtEmail.value;
    if(email.indexOf(".",0)==-1){
        console.log("电子邮件格式不正确\n必须包含字符.");
        return false;
        }
    return true;
    }
//-->
</script>
</head>

<body>
    <form name="myform" onsubmit="registerform( );" method="post">
        <table>
            <tr>
                <td>会员名:</td>
                <td><input type="text" id="txtName" required>(可包含 a-z、0-9 和下划线)</td>
            </tr>
            <tr>
                <td>密码:</td>
                <td><input type="password" id="txtPassword" required>(至少包含 6 个字符)</td>
            </tr>
            <tr>
                <td>邮箱:</td>
                <td><input type="email" id="txtEmail" required>(至少包含 6 个字符)</td>
            </tr>
            <tr>
               <td>
                    <input type="reset" value="重置" id="txtReset">
                </td>
                <td>
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/236310536936129.png "#left")

                    <input type="submit" value="登录" id="txtRegister">
                </td>
            </tr>
        </table>
    </form>
</body>
</html>
  • 写回答

1条回答 默认 最新

  • 崽崽的谷雨 2021-12-16 14:53
    关注

    你用正则 不香吗?

    评论

报告相同问题?

问题事件

  • 创建了问题 12月16日

悬赏问题

  • ¥15 求解决扩散模型代码问题
  • ¥15 工创大赛太阳能电动车项目零基础要学什么
  • ¥20 limma多组间分析最终p值只有一个
  • ¥15 nopCommerce开发问题
  • ¥15 torch.multiprocessing.spawn.ProcessExitedException: process 1 terminated with signal SIGKILL
  • ¥15 QuartusⅡ15.0编译项目后,output_files中的.jdi、.sld、.sof不更新怎么解决
  • ¥15 pycharm输出和导师的一样,但是标红
  • ¥15 想问问富文本拿到的html怎么转成docx的
  • ¥15 我看了您的文章,遇到了个问题。
  • ¥15 GitHubssh虚拟机连接不上