I got a form with Password and Confirm Password fields and I would like to validate that they got the same value without extra buttons.
Here is my code:
<input type="password" id="password" name="password" ng-model="password" placeholder='Password'
ng-pattern="/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])[A-Za-z\d$@$!%*?&]{6,20}/";
ng-blur="focused4 = false" ng-focus="focused4 = true"
ng-minlength="6" ng-maxlength="20" required>
<span ng-show="focused4 && !regForm.password.$valid"><error>6 to 20 characters, one numeric digit, one upper case letter, one lower case letter and a special character</error></span>
</td>
<td align="left">
<span ng-show="regForm.password.$valid"><valid>✔</valid></span>
<span ng-show="!regForm.password.$valid"><error>❌</error></span>
</td>
</tr>
<tr>
<td align="left">
<input type="password" id="passwordConfirm" name="passwordConfirm" ng-model="passwordConfirm" placeholder="Confirm Password"
ng-pattern="/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])[A-Za-z\d$@$!%*?&]{6,20}/";
ng-blur="focused5 = false" ng-focus="focused5 = true"
ng-minlength="6" ng-maxlength="20" required>
<span ng-show="focused5 && !regForm.passwordConfirm.$valid" ><error>Passwords are not correct or don't match</error></span>
<span ng-show="regForm.password.value != regForm.passwordConfirm.value"> NOT MATCHED </span>
<span ng-show="regForm.password.value == regForm.passwordConfirm.value"> MATCHED </span>
</td>
And this how it looks like (I think, there are no updates while I'm changing the value):
I researched:
Comparing two input values in a form validation with AngularJS
Angularjs check and compare two input field values
but itlooks like something not working in my case... I also researched directive AngularJS compare password fields but I would like to make the page as simple as possible.
Any advises?
UPDATE 1
If I'm changing my password confirmation field to:
<td align="left">
<input type="password" id="passwordConfirm" name="passwordConfirm" ng-model="passwordConfirm" placeholder="Confirm Password"
ng-pattern="password";
ng-blur="focused5 = false" ng-focus="focused5 = true"
ng-minlength="6" ng-maxlength="20" required>
<span ng-show="focused5 && !regForm.passwordConfirm.$valid" ><error>Passwords are not correct or don't match</error></span>
<span ng-show="!regForm.passwordConfirm.$valid"> NOT MATCHED </span>
<span ng-show="regForm.passwordConfirm.$valid"> MATCHED </span>
</td>
there is a one small bug there: 1) Add password 2) Add Confirmation password == password 3) Delete password 4) System still shows matching 5) Add password which is not valid (like too short) 5) System still shows that they are matching
But, it's ok for me, cause when the password validation passed - confirmation shows error again and I can't save value. If there is better solution, just let me know.