Solved

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

Posted on 2014-03-20
4
606 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Find out what you should include to make the best professional email signature for your organization.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
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…

776 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