We help IT Professionals succeed at work.

Can I use one RequiredFieldValidator for multiple controls?

Hello I have a series of text boxes to record telephone numbers.  Like this:
Phone Number: (<asp:TextBox ID="txtContHomePh1" runat="server" MaxLength="3" Width="32px"></asp:TextBox>
                       )
                       <asp:TextBox ID="txtContHomePh2" runat="server" MaxLength="3" Width="31px"></asp:TextBox>
                       &nbsp;-
                       <asp:TextBox ID="txtContHomePh3" runat="server" MaxLength="4" Width="49px"></asp:TextBox>

Open in new window

txtContHomePh1 is the area code, txtContHomePh2 is for the next 3 number, and txtContHomePh3 is for the last 4 digits. I want a RequiredFieldValidator to make sure the user fills out the boxes.  Can I use just 1 for all 3 textboxes? Or do I have to put one on each text box?
Comment
Watch Question

Top Expert 2010
Commented:
You need one for each input.

Author

Commented:
thank you @zephyr_hex (Megan).   I was hoping there was another way.  I appreciate you responding so quickly.
Top Expert 2010

Commented:
If you wanted to use jQuery / JavaScript instead, you could use a class on your required elements and bind them to one function that handles the validation.
But ASP .NET validation controls can only be linked to one control.