Solved

How do you use RequiredFieldValidator with a MaskedEditExtender.

Posted on 2008-10-09
3
3,206 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

627 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