2013-06-02 167 views
0

在單個頁面上使用多形式驗證Clay Campbell從jsfiddle和Stackoverflow借用了重大修改5-28-2013 這是使用jQuery Validate liberary Murach jQuery本書也用過當我嘗試執行jQuery驗證代碼時出現錯誤

$(document).ready(function() { 

    $.validator.setDefaults({ 
     //debug: true, // blocks submit 
     errorElement: 'span', //default input error message container 
     errorClass: 'help-inline', // default input error message class 
     focusInvalid: false, // do not focus the last invalid input) 
     highlight: function (element) { // hightlight error inputs 
      $(element).closest('.control-group').addClass('error'); // set error class to the control group 
     }, 
     unhighlight: function (element) { // revert the change done by hightlight 
      $(element).closest('.control-group').removeClass('error'); // set error class to the control group 
     }, 
}); // end ready function 

// init validator obj and set the rules for registrationForm 
$('#registrationForm').validate({ 
    rules: { 
     email: { 
      required: true, 
      email: true 
     }, 
     password: { 
      required: true, 
      minlength: 6 
     }, 
     verify: { 
      required: true, 
      equalTo: "#password" 
     }, 
     firstName: { 
      required: true 
     }, 
     lastName: { 
      required: true 
     }, 
     address: { 
      required: true 
     }, 
     city: { 
      required: true 
     }, 
     state: { 
      required: true, 
      rangelength: [2, 2] 
     }, 
     zip: { 
      required: true, 
      rangelength: [5, 10] 
     }, 
     phone: { 
      required: true, 
      phoneUS: true 
     } 
    } 
}); // end jQuery validation method call for registrationForm 

// init validator obj and set the rules rules for memberForm 
$('#memberForm').validate({ 
    rules: { 
     emailMem: { 
      required: true, 
      email: true 
     }, 
     passwordMem: { 
      required: true, 
      minlength: 6 
     } 
    } 
}); // end jQuery validation method call for memberForm 
+0

它給SCRIPT1009:預期「}」行72字符60我也有HTML代碼,以及我不知道如何將它融入這裏我已經從查看其他問題中獲得了很多幫助。 –

+0

您有語法錯誤。如錯誤信息所示,請仔細檢查括號。 – Sparky

回答

0

你有語法錯誤,如下所示...

$(document).ready(function() { 

    $.validator.setDefaults({ 
     //debug: true, // blocks submit 
     errorElement: 'span', //default input error message container 
     errorClass: 'help-inline', // default input error message class 
     focusInvalid: false, // do not focus the last invalid input) 
     highlight: function (element) { // hightlight error inputs 
      $(element).closest('.control-group').addClass('error'); // set error class to the control group 
     }, 
     unhighlight: function (element) { // revert the change done by hightlight 
      $(element).closest('.control-group').removeClass('error'); // set error class to the control group 
     }, // <-- REMOVE THIS TRAILING COMMA 
    });  // <-- ADD THIS LINE 

// }); // end ready function // <-- MOVE THIS LINE TO END 

    // init validator obj and set the rules for registrationForm 
    $('#registrationForm').validate({ 
     rules: { 
      email: { 
       required: true, 
       email: true 
      }, 
      password: { 
       required: true, 
       minlength: 6 
      }, 
      verify: { 
       required: true, 
       equalTo: "#password" 
      }, 
      firstName: { 
       required: true 
      }, 
      lastName: { 
       required: true 
      }, 
      address: { 
       required: true 
      }, 
      city: { 
       required: true 
      }, 
      state: { 
       required: true, 
       rangelength: [2, 2] 
      }, 
      zip: { 
       required: true, 
       rangelength: [5, 10] 
      }, 
      phone: { 
       required: true, 
       phoneUS: true 
      } 
     } 
    }); // end jQuery validation method call for registrationForm 

    // init validator obj and set the rules rules for memberForm 
    $('#memberForm').validate({ 
     rules: { 
      emailMem: { 
       required: true, 
       email: true 
      }, 
      passwordMem: { 
       required: true, 
       minlength: 6 
      } 
     } 
    }); // end jQuery validation method call for memberForm 

}); // end ready function // <-- MOVED TO END 
+0

好的,謝謝你這就是我要找的謝謝斯帕奇! –

相關問題