1

I am working on a simple user registration form in my Angular1x app. I want to ensure that 'password' and 'password_confirm match. If they do not match the form should be invalid. I can display validation messages if the input does not match but the form is not invalid menaing that it can be submitted:

<div class="form-group input text required " ng-class="{'has-error': userRegister.$submitted && password !== password_confirm}">
     <input class="form-control" type="text" name="password_confirm" placeholder="Password Confirm" ng-model="password_confirm" equals="{{password}}" required="required" id="password-confirm" />
</div>

I tried adding the 'equals' attribute which I read aboiut, but again it does not invalid the form.

Any ideas?

2
  • Is the equals="{{passwor}}d" just a tippo? Commented Jul 15, 2020 at 10:44
  • It's a typo - question updated Commented Jul 15, 2020 at 10:58

1 Answer 1

1

I've created a small fiddle that does the trick with ng-pattern="(password)" So the second input could look like this:

 <input class="form-control" type="text" name="password_confirm" placeholder="Password Confirm" ng-model="password_confirm" ng-pattern="(password)" required="required" id="password-confirm" />
Sign up to request clarification or add additional context in comments.

3 Comments

This works perfectly with invalid form status if the password do not match.
having tested this the solution doesn't work - see my modified fiddle jsfiddle.net/c58dfeka
Update at jsfiddle.net/sL0ojhe9 the pattern is based on the model variable of the first password.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.