I have a web form with some fields for Social Security Number and phone number, so I have textboxes set up with MaskedEditExtenders to enforce the proper format during entry. I had used both a RequiredFieldValidator and RegularExpressionValidator to do this, as well as added ValidationCalloutExtenders to both validators. The problem is that when the submit button is clicked, the fields say they values aren't in the right format -- the RegularExpressionValidator is saying this and the RequiredFieldValidator doesn't appear to be working.
I realize the mask might be causing the RequiredFieldValidator to think a value is provided, so I changed the InitialValue of match the prompt, but that didn't work. I also tried various combinations of the MaskedEditExtender's properties, namely ClearMaskOnLostFocus and ClearTextOnInvalid. No matter what I do this doesn't work the way I want to.
I was looking through one of my books and I found the MaskedEditValidator, thinking this might help deal with this issue, so I tried it, but still I can't get the results I'm looking for. If the field with the mask is empty, I need to show a message saying the field is required. If the entered data doesn't match the format, I want to display a message saying the entered data isn't in the correct format. I've spent a whole day trying to figure this out and I'm stumped. Below is code that does nothing but collect the SSN. Please tell me what I need to change to get this working. Thanks.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="MaskedEditTest.Default" %><%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="act" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><title></title></head><body><form id="form1" runat="server"><act:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" EnableViewState="false" /><div><asp:Label ID="lblSSN" runat="server" AssociatedControlID="txtSSN" EnableViewState="false" Text="SSN *:" /><asp:TextBox ID="txtSSN" runat="server" autocomplete="off" AutoCompleteType="Disabled" Columns="11" MaxLength="11" /><act:MaskedEditExtender ID="meeSSN" runat="server" EnableViewState="false" Mask="999-99-9999" MaskType="Number" TargetControlID="txtSSN" /><act:MaskedEditValidator ID="mevSSN" runat="server"
ControlExtender="meeSSN"
ControlToValidate="txtSSN"
Display="None"
EmptyValueMessage="SSN is required"
EnableViewState="false"
InvalidValueMessage="SSN must be valid"
IsValidEmpty="false"
SetFocusOnError="true"
ValidationExpression="^\d{3}-\d{2}-\d{4}$"
/><act:ValidatorCalloutExtender ID="vceSSN" runat="server" EnableViewState="false" TargetControlID="mevSSN" /><br /><asp:Button ID="btnSubmit" runat="server" EnableViewState="false" OnClick="btnSubmit_Click" Text="Submit" /></div></form></body></html>