?
Solved

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

Posted on 2014-03-20
4
Medium Priority
?
718 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 83

Accepted Solution

by:
leakim971 earned 2000 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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

809 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