javascript - validation is not correct when no elements type in the confirm password text box -


how check validation of password. in below when try type in password text field , if ignore confirm password text field, still can submitted. if type in confirm password text field it'll check password text field, whether inputs same or not.

fiddle

<head>     <meta http-equiv="content-type" content="text/html; charset=utf-8">      <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.js"></script>       <link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">     <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>       <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/jquery.bootstrapvalidator/0.5.3/css/bootstrapvalidator.min.css"/>     <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery.bootstrapvalidator/0.5.3/js/bootstrapvalidator.min.js"> </script> </head> <body>     <form id="enableform" class="form-horizontal">         <div class="form-group">             <label class="col-xs-3 control-label">new password</label>             <div class="col-xs-5">                 <input type="password" class="form-control" name="password" />             </div>         </div>          <div class="form-group">             <label class="col-xs-3 control-label">confirm_password</label>             <div class="col-xs-5">                 <input type="password" class="form-control" name="confirm_password" />             </div>         </div>         <div class="form-group">             <div class="col-md-9 col-md-offset-3">                 <button type="submit" class="btn btn-default">validate</button>             </div>         </div>     </form>      <script type="text/javascript">         $(document).ready(function() {             $('#enableform').bootstrapvalidator({                 container: '#messages',                 feedbackicons: {                     valid: 'glyphicon glyphicon-ok',                     invalid: 'glyphicon glyphicon-remove',                     validating: 'glyphicon glyphicon-refresh'                 },                 fields: {                     password: {                         enabled: false,                         validators: {                             notempty: {                                 message: 'the password required , cannot empty'                             }                         }                     },                     confirm_password: {                         enabled: false,                         validators: {                             notempty: {                                 message: 'the confirm password required , cannot empty'                             },                             identical: {                                 field: 'password',                                 message: 'the password , confirm must same'                             }                         }                     }                 }             })             // enable password/confirm password validators if password not empty             .on('keyup', '[name="password"]', function() {                 var isempty = $(this).val() == '';                 $('#enableform')                 .bootstrapvalidator('enablefieldvalidators', 'password', !isempty)                 .bootstrapvalidator('enablefieldvalidators', 'confirm_password', !isempty);                  // revalidate field when user start typing in password field                 if ($(this).val().length == 1) {                     $('#enableform').bootstrapvalidator('validatefield', 'password')                     .bootstrapvalidator('validatefield', 'confirm_password');                 }             });         });     </script> </html> 


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -