Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do you use RequiredFieldValidator with a MaskedEditExtender.

Posted on 2008-10-09
3
Medium Priority
?
3,275 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 1500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

886 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