javascript表单验证Uncaught SyntaxError:意外的令牌

时间:2015-08-22 19:54:41

标签: javascript

我的表格没有验证;当我提交表格时,它就会清除,即使它没有正确填写。我一直在寻找不同的方法来验证这一点,这是最不复杂的。我已经尝试过其他人,无论如何我都会得到同样的东西。

function validate() {
    var fname=document.myForm.fName;
    var lname=document.myForm.lName;
    var age=document.myForm.uAge;
    var uname=document.myForm.userName;
    var email=document.myForm.eMail;
    var pass=document.myForm.password;
    var rpass=document.myForm.repass;
    var disp=document.myForm.display;
    var udate=document.myForm.update;
    if(fname.value < 3) {
        window.alert("First name must be atleast 3 characters!");
        name.focus();
        return false;
    }
    if(lname.value < 3) {
        window.alert("Last name must be atleast 3 characters!");
        name.focus();
        return false;
    }
    if(age.value < 14 || > 110) {
        window.alert("You must be between ages 14 & 110");
        name.focus();
        return false;
    }
    if(uname.value < 5) {
        window.alert("You must have a user name of 5 characters!");
        name.focus();
        return false;
    }
    if(email.value.indexOf("@", 0) < 0) {
        window.alert("Email Invalid!");
        email.focus();
        return false;
    }
    if(email.value.indexOf(".", 0) < 0) {
        window.alert("Email Invalid!");
        email.focus();
        return false;
    }
    if(pass.value < 8) {
        window.alert("Password must be 8 characters long");
        pass.focus();
        return false;
    }
    if(rpass.value !=pass) {
        window.alert("Passwords do not match!);
        rpass.focus();
        return();
    }
}

HTML:

<div id="menubar">
<a href="homepage.html" class="button">Home</a>
<a href="lucyreview.html" class="button">Lucy</a>
<a href="insurgentreview.html" class="button">Insurgent</a>
<a href="almanacreview.html" class="button">Proj.Almanac</a>
<a href="registryForm.html" class="button">Register</a>
</div>

<div id="registry">
<form name="myForm" onsubmit="return(validate())">
<table cellspacing="2px" cellpadding="2px" border="1px">
<tr><td>First Name: </td><td><input name="fName" type="text" placeholder="Enter First Name" required /></td></tr>

<tr><td>Last Name: </td><td><input name="lName" type="text" placeholder="Enter Last Name" required /></td></tr>

<tr><td>Age: </td><td><input name="uAge" type="number" placeholder="Enter your Age" required /></td></tr>

<tr><td>User Name: </td><td><input name="uName" type="text" placeholder="Enter desired User Name" required/></td></tr>

<tr><td>Email: </td><td><input type="eMail" name="email" placeholder="Enter Email address" required /></td></tr>

<tr><td>Password(8 Char.): </td><td><input name="password" type="password" placeholder="Enter 8 character Password" required /></td></tr>

<tr><td>Re-Enter Password: </td><td><input name="rePass" type="password" placeholder="Re-Enter Password" required /></td></tr>

<tr><td><input type="checkbox" name="display">Check to display info to public</td></tr>

<tr><td><input type="checkbox" name="updates" />Check to recieve updates</td></tr>
</table>
<input type="submit" value="submit" onclick="validate()" />
<input type="reset" value="Reset" name="reset" onclick="changeBack()">
<button type="button" onclick="backgroundChange()">Set background color</button>    

0 个答案:

没有答案