asp.net mvc - Jquery validation triggers but doesn't prevent the form submitting -


i have mvc project knockout.

i'm trying validate register view using jquery validation.

this register view:

<form data-bind="submit: register" id="formregister">     <label>email</label>     <input id="registeremail" name="registeremail" class="required email form-control"             type="text" data-bind="value: registeremail" />      <label>password</label>     <input id="registerpassword" name="registerpassword" class="required form-control"             type="password" data-bind="value: registerpassword" />      <label>confirm password</label>     <input id="registerpassword2" name="registerpassword2" class="required form-control"             type="password" data-bind="value: registerpassword2" />      <button type="submit" class="btn btn-default">register</button> </form> 

and jquery:

$(function () {     $(document).ready(function () {         $("#formregister").validate();         $.extend($.validator.messages, { required: "*", email: "invalid email address." });     }); }); 

when submit form, validation triggered form also being submitted.

you have return false if form not valid.

$(document).on("submit", "#formregister", function(evt) {       if(!$(evt.target).valid()) { return false; }  }); 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -