0

I'm trying to implement a form validation using only the view - i'm trying to avoid creating a new directive for this.

Question - is possible to validate matching password only using the partial/view e.g:

div(ng-class="{true: 'no-match'}[password != password2]")

any tip will be gladly appreciated :)

1
  • anyway i could validate password2 w/o been ng-modal? I need to validate the form but not pass the value of password2 on submit Commented Jun 16, 2015 at 5:48

1 Answer 1

1

Yes it is possible ,

<input name="password" ng-class = "{valid: (password1 == password2),
                    invalid: (password1 != password2) }" ng-pattern="/[0-9]/">

where, valid and invalid are css classes,

to display an error message regarding that, use

<div id="invalidEmail" class="mismatch"
    ng-show="testForm.password.$error.pattern && !testForm.password.$pristine">
    Please enter atleast a number
</div>

where testForm is your form name like

<form name="testForm"> </form>

For more reference you can see the link http://www.ng-newsletter.com/posts/validations.html

Sign up to request clarification or add additional context in comments.

6 Comments

anyway i could validate password2 w/o been ng-modal? I need to validate the form but not pass the value of password2 on submit
in your controller code, in the submit function delete password2 from formdata , using delete $scope.formdata.password2;
what if i want the password to contain at least a number?
then simple use a regex as pattern
I have edited the answer , i think it will be helpful
|

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.