Menu

Password Match Angularjs Validation

The password field binding should work, but you are validating that the password field should be at least 6 characters long, meaning it will be bound to model only after you enter 6 or more characters. Until then it will be undefined, which is what you are getting in the console.log statement I assume.


However there is other problem. The error message will not be shown, because your field name is confirm-password. You should name it confirmPassword or something without dashes. The name is used by Angular as an object property and JavaScript object key can not contain dashes.


So the password confirm part of your form should look something like this:


<div class="form-group" ng-class="{ 'has-error': form.confirmPassword.$invalid && !form.confirmPassword.$pristine }">
    <label for="confirm-password">Confirm Password</label>
    <input type="password" name="confirmPassword" id="confirm-password" class="form-control" ng-model="user.confirmpwd" required equal="{{user.password}}"/>
    <span ng-show="form.confirmPassword.$error.equal" class="help-block">Password does not match above</span>
</div>

552
Search

Ads