• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 811
  • Last Modified:

angular how do you validate that one of two text boxes has a value

I have two text boxes and I want to validate that one of them was filled in.

<input type="TextBox" name="TextBoxEmailAddress1" ng-model="emailAddress1"/>
<input type="TextBox" name="TextBoxEmailAddress2" ng-model="emailAddress2"/>

Thanks!
0
jackjohnson44
Asked:
jackjohnson44
  • 2
1 Solution
 
Kyle HamiltonData ScientistCommented:
do you mean a user must provide an email but it doesn't matter which field they use?

why not just make the first one required and the second one optional?
0
 
jackjohnson44Author Commented:
I can't change the requirement.  I need to validate that one of the two is filled in. It's a lot more complicated that my simple example.  I can't change the requirement at all.
0
 
leakim971PluritechnicianCommented:
Test page : http://jsfiddle.net/nZpZW/2/

<div ng-app="App" ng-controller="Ctrl">
    <form name="form" class="css-form" novalidate>
        <input type="email" name="TextBoxEmailAddress1" ng-model="emailAddress1" ng-required="!emailAddress2" />
        <br />
        <input type="email" name="TextBoxEmailAddress2" ng-model="emailAddress2" ng-required="!emailAddress1" />
        <br />
        <span ng-show="form.TextBoxEmailAddress1.$error.required||form.TextBoxEmailAddress2.$error.required">FILL AT LEAST ONE</span>
        <br />
        <input type="submit" value="SUBMIT"  />
    </form>
</div>

Open in new window

0
 
jackjohnson44Author Commented:
Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now