Solved

How do you use RequiredFieldValidator with a MaskedEditExtender.

Posted on 2008-10-09
3
3,102 Views
Last Modified: 2013-11-26
I have a text box for a phone number with a MaskedEditExtender. However I'm also trying to add a RequiredFieldValidator. However the validator counts an empty mask as the textbox being populated.

Is there a way to get the validator to ignore the mask?

Code below.  


               
<asp:TextBox ID="txtPhone" runat="server" Text='<%# Bind("Phone") %>' Width="100px"/>

                    <cc1:MaskedEditExtender ID="MaskedEditExtender4" runat="server" TargetControlID="txtPhone" ClearMaskOnLostFocus="false"   Mask="(999)999-9999"  >

                    </cc1:MaskedEditExtender>

                     <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="Required Field" ControlToValidate="txtPhone"></asp:RequiredFieldValidator>

Open in new window

0
Comment
Question by:Darebear
3 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 22685088
You can use the customvalidator instead. Although it performs server side validation, that can be compensated by using AJAX or you could use client side javascript.
0
 

Author Comment

by:Darebear
ID: 22962842
Here's a final solution that works for those searching..  Phone Number with a mask that allows you to confirm a number entered even when the mask is preserved on lost focus.

Enjoy


<asp:TextBox ID="txtPhone" runat="server" Text='<%# Bind("Phone") %>' />

                             <cc1:MaskedEditExtender ID="MaskedEditExtender4" runat="server"  ClearMaskOnLostFocus="false" Mask="(999)999-9999" TargetControlID="txtPhone">

                                                    </cc1:MaskedEditExtender>

                                                   <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"  ControlToValidate="txtPhone"

                            ErrorMessage="Please enter a contact phone number" 

                            ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}"></asp:RegularExpressionValidator>

Open in new window

0
 

Expert Comment

by:TrafficTechDev
ID: 23737593
yes, but what if I want to allow empty phone number and only validate it if the user typed 4 characters out the 10?
this validator always get fire, she I don't want to.
I want it to get fire only if the input is not valid.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

16 Experts available now in Live!

Get 1:1 Help Now