Validating only one of two controls

  • Thread starter Thread starter Darrel
  • Start date Start date
D

Darrel

(whew...I'm full of questions tonight!)

I have two textBoxes that I need to validate. One's a phone number and one's
an email address. I need to only validate one of them, though. (ie, only
email or only phone are required).

How can I do this? I've set up a custom control the checks both of these
fields and if they're both blank, it returns a 'one of the two must be
filled in' error.

I think I'd like to do something like this:

if textbox.text > "" then validate with regex validator

but I'm not sure how to go about that.
 
Darrel..place CausesValidation="False" to the button !
like:-
<asp:Button runat="server" id="YourIDButton" text="YourText"
CausesValidation="False"></asp:Button>
Hope i understand what u want!
 
I built a replacement to Microsoft's validators that handles this.
"Professional Validation And More"
(http://www.peterblum.com/vam/home.aspx) includes 22 validators. Its
MultiConditionValidator is designed for this. It lets you merge the logic
of other validators together into a boolean expression like "TextBox1 is
Required OR TextBox2 is Required". It generates the javascript for you.
All javascript runs on IE, IE/Mac, Netscape/Mozilla/FireFox, Opera 7 and
Safari whereas Microsoft's only handles the IE browsers.

Peter:

A belated thanks for your answer! I'll definitely take a look at that.

The custom validator makes sense. Actually, in this case, I was able to get
away with having the custom validator check to make sure they aren't both
empty. Then, I validated both with a regex. The regex checks for either a
valid entry OR a blank field. So, in the end, that worked. At least for
these two particular fields.

-Darrel
 
Back
Top