Solved

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

Posted on 2014-03-20
4
600 Views
Last Modified: 2014-04-01
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
Comment
Question by:jackjohnson44
  • 2
4 Comments
 
LVL 25

Expert Comment

by:Kyle Hamilton
ID: 39944955
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
 

Author Comment

by:jackjohnson44
ID: 39957269
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
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39957528
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
 

Author Closing Comment

by:jackjohnson44
ID: 39969541
Thanks!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now