Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do you use RequiredFieldValidator with a MaskedEditExtender.

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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

715 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