未捕获的语法错误:如果出现意外的令牌

时间:2016-04-22 18:01:11

标签: javascript

if (fname == null || fname == "") {

获取“未捕获的语法错误:第13行中的意外令牌”。它在Javascript lint中说“SyntaxError:missing variable name”

function validateregistration() {

    var emailRegex = /^[A-Za-z0-9._]*\@[A-Za-z]*\.[A-Za-z]{2,5}$/;    
    var fname = document.form.user_firstname.value,
        lname = document.form.user_lastname.value,
        uname = document.form.username.value,
        femail = document.form.email.value,
        freemail = document.form.verify_email.value,
        fpassword = document.form.password.value,


        if (fname == null || fname == "") {
            document.form.user_firstname.focus();
            document.getElementById("errorBox")
                .innerHTML = "enter the first name";
            return false;
        }
    if (lname == null || lname == "") {
        document.form.user_lastname.focus();
        document.getElementById("errorBox")
            .innerHTML = "enter the last name";
        return false;
    }

    if (femail == null || femail == "") {
        document.form.email.focus();
        document.getElementById("errorBox")
            .innerHTML = "enter the email";
        return false;
    } else if (!emailRegex.test(femail)) {
        document.form.Email.focus();
        document.getElementById("errorBox")
            .innerHTML = "enter the valid email";
        return false;
    }

    if (freemail == null || freemail == "") {
        document.form.verify_email.focus();
        document.getElementById("errorBox")
            .innerHTML = "Re-enter the email";
        return false;
    } else if (!emailRegex.test(freemail)) {
        document.form.enterEmail.focus();
        document.getElementById("errorBox")
            .innerHTML = "Re-enter the valid email";
        return false;
    }


    if (fpassword == null || fpassword == "") {
        document.form.password.focus();
        document.getElementById("errorBox")
            .innerHTML = "enter the password";
        return false;
    }    

}

4 个答案:

答案 0 :(得分:1)

此行未正确终止var语句:

fpassword = document.form.password.value,

在该行的末尾使用分号:

fpassword = document.form.password.value;

if (fname == null || fname == "") {

答案 1 :(得分:0)

最后一个变量定义(fpassword)以逗号

结尾

答案 2 :(得分:0)

更改此部分:

    fpassword = document.form.password.value; // <--


    if (fname == null || fname == "") {

答案 3 :(得分:0)

变量行未终止

var fname = document.form.user_firstname.value,
        lname = document.form.user_lastname.value,
        uname = document.form.username.value,
        femail = document.form.email.value,
        freemail = document.form.verify_email.value,
        fpassword = document.form.password.value;