Solved

How do you use RequiredFieldValidator with a MaskedEditExtender.

Posted on 2008-10-09
3
3,072 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

13 Experts available now in Live!

Get 1:1 Help Now