Hello I am trying to create a simple form with a password and confirm-password inputs.
I found out that 'ng-pattern' and 'ng-match' don't work so good together. Until the password tag is not populated with a value,and it doesn't until it matches the ng-pattern restriction, he is on the local scope empty and because of the 'ng-match' directive between password tag and and confirm-password tag I always see an error "error passwords dont much" even when the are the same.
Is there any way around this?
Thanks
$scope.ok = function (){};
$scope.password = '';
$scope.confirmPassword = '';
$scope.passwordRegex ='(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{6,})$';
<form name="form" class="form-horizontal" novalidate>
<div class="form-group">
<label> Password: </label>
<input name="password" type="password"
placeholder="Password" required
ng-model="password"
ng-pattern="passwordRegex" />
</div>
<div ng-show="form.$submitted && form.password.$invalid">
<div ng-show="form.password.$error.required">
RequiredField</div>
<div ng-show="form.password.$error.pattern">
InvalidPassword</div>
</div>
<div class="form-group">
<label>ConfirmPassword:</label>
<input name="confirmPassword" type="password"
placeholder="ConfirmPassword" required
ng-model="confirmPassword"
ng-match="password" />
</div>
<div
ng-show="password != confirmPassword">
<div ng-show="form.confirmPassword.$error.match">
PasswordMismatch</div>
</div>
<div ng-show="form.$submitted &&
form.confirmPassword.$invalid">
<div ng-show="form.confirmPassword.$error.required">
RequiredField</div>
</div>
<button type="submit" ng-click="!form.$invalid &&
testCtrl.ok()">Ok</button>
</form>