OK. Three years later I just spent an hour or two on the darn MaskedEditExtender... I think I may have nailed a solution to the problem of optional phone numbers (not a required field), but I haven't tested it thoroughly yet. The key was to actually include
the mask ___-___-____ in the Regular Expression pattern as an option. I'll actually USE the MaskedEditExtender if this solution works! I get to keep ClearMaskOnLostFocus="false" so the hyphens-dashes don't go away and I get to store only RAW numbers in the
database and format them for display only (the desired result)... I have no idea why I would want a MaskedEditValidator... I'm not sure what it gains me if anything... this should have been built into it to ignore the underscores!!!
manbanner
Member
10 Points
5 Posts
Re: Can't get MaskedEditExtender/Validator to work
Aug 24, 2011 01:54 AM|LINK
OK. Three years later I just spent an hour or two on the darn MaskedEditExtender... I think I may have nailed a solution to the problem of optional phone numbers (not a required field), but I haven't tested it thoroughly yet. The key was to actually include the mask ___-___-____ in the Regular Expression pattern as an option. I'll actually USE the MaskedEditExtender if this solution works! I get to keep ClearMaskOnLostFocus="false" so the hyphens-dashes don't go away and I get to store only RAW numbers in the database and format them for display only (the desired result)... I have no idea why I would want a MaskedEditValidator... I'm not sure what it gains me if anything... this should have been built into it to ignore the underscores!!!
<asp:TextBox ID="txtCellPhone" runat="server" /> <ajaxToolkit:MaskedEditExtender TargetControlID="txtCellPhone" Mask="999-999-9999" runat="server" ClearMaskOnLostFocus="false" /> <asp:RegularExpressionValidator ID="valCellPhoneRegex" runat="server" ControlToValidate="txtPhone2" ValidationExpression="(___-___-____)|(\d{3}-\d{3}-\d{4})" ErrorMessage=""Cell Phone" must be 7 digits xxx-xxx-xxxx" Display="dynamic" />