After about two hours of fiddling with it myself and searching the 'Net for anything that would help, I haven't run across anything that seems to help.
As you can see, I'm simply trying to allow only numbers to be entered in the textbos and validate for an SSN in the format ###-##-####. I've tried everything I can think of and my own social security number won't even validate! [:O]
I'd really appreciate it if someone can tell me what I'm doing wrong/missing!
Thanks...
"f u cn rd ths, u cn gt a gd jb n cmptr prgmmng." - Anon
Your validation group on your MaskedEditValidator is different than your textbox.
Brian
"Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
While you were right in pointing that out, that oversight unfortunately didn't solve my problem...
Wierd thing is, I've got a date textbox with a maskededitextender/validator and calendarextender attached to it and that works just fine. [8-)]
I just "modeled" the ssn textbox after the date textbox, figuring if the one worked, then the other should. But noooo!
Here's the code for both:
<asp:TemplateField HeaderText="Hire Date">
<InsertItemTemplate>
<ajaxToolkit:MaskedEditExtender
ID="editExtHireDate"
runat="server"
TargetControlID="txtHireDate"
Mask="99/99/9999"
MaskType="Date"
MessageValidatorTip="True"
OnFocusCssClass="MaskedEditFocus"
OnInvalidCssClass="MaskedEditError"
ErrorTooltipEnabled="True" />
<ajaxToolkit:MaskedEditValidator
ID="editValidatorHireDate"
runat="server"
ControlExtender="editExtHireDate"
ControlToValidate="txtHireDate"
IsValidEmpty="True"
InvalidValueMessage="Date is invalid. Select a date from the calendar or enter the format mm\dd\yyyy."
Display="Dynamic"
InvalidValueBlurredMessage="*"
ValidationGroup="valHireDate"
ValidationExpression="(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d" />
<ajaxToolkit:CalendarExtender
ID="calExtHireDate"
runat="server"
Enabled="True"
TargetControlID="txtHireDate"
Format="MM/dd/yyyy">
</ajaxToolkit:CalendarExtender>
<asp:TextBox
ID="txtHireDate"
runat="server"
Text='<%# Bind("HireDate") %>'
Width="160px"
Font-Size="10px"
ValidationGroup="valHireDate" />
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="SSN">
<InsertItemTemplate>
<ajaxToolkit:MaskedEditExtender
ID="editExtSSN"
runat="server"
TargetControlID="txtInsSSN"
Mask="999-99-9999"
MaskType="None"
MessageValidatorTip="True"
OnFocusCssClass="MaskedEditFocus"
OnInvalidCssClass="MaskedEditError"
ErrorTooltipEnabled="True" />
<ajaxToolkit:MaskedEditValidator
ID="editValidatorSSN"
runat="server"
ControlExtender="editExtSSN"
ControlToValidate="txtInsSSN"
IsValidEmpty="True"
InvalidValueMessage="Entry is invalid."
Display="Dynamic"
InvalidValueBlurredMessage="*"
ValidationGroup="valSSN"
ValidationExpression="(\d{3})[--.](\d{2})[--.](\d{4})" />
<asp:TextBox
ID="txtInsSSN"
runat="server"
Width="160px"
Font-Size="10px"
ValidationGroup="valSSN" />
</InsertItemTemplate>
</asp:TemplateField>
Aside from the SSN textbox not being validated right, it also isn't keeping the dashes after the textbox loses focus. But the dashes return upon gaining focus again. I'm stumped...
HELP! [:O]
"f u cn rd ths, u cn gt a gd jb n cmptr prgmmng." - Anon
I have the same type of MaskedEdit control (i.e. SSN Input field) and mine works fine. The difference is I don't have the ValidationExpression and ValidationGroup on mine. I'd at least remove the ValidationExpression because it's unnecessary. :)
Thanks for replying Rick, but unfortunately that didn't solve the problem either.
You say yours is the same except for the group and expression, but there's got to be something else going on that I'm overlooking.
Removing the validation group doesn't make a difference. I.e. it doesn't seem that it's needed here, but removing the validation expression allowed
anything to go through, as long as it was a number - even less than nine digits. However, when "MaskType" is set to "Number", rather than "None" and I type in less than nine digits, when the textbox loses focus the rest of the spaces are filled
in with zeros!
Could someone PLEASE explain to me what the heck is going on with this thing and hwo to get it to work the way I need it to!?!?!
Okay - yes, I'm a little frustrated...
"f u cn rd ths, u cn gt a gd jb n cmptr prgmmng." - Anon
OK....first of all to get rid of the zeros set AutoComplete=false. That way it won't fill in empty spaces. Second, I think I've got it to work but had to add a RegularExpressionValidator and another ValidationCalloutExtender (see below). I tested this
and it works for me. [:)]
HTH,
Rick
<asp:TextBox
ID="Zip"
runat="server"></asp:TextBox>
<cc1:MaskedEditExtender
ID="ZipMask"
runat="server"
AutoComplete="false"
ErrorTooltipEnabled="true"
InputDirection="LeftToRight"
Mask="99999-9999"
MaskType="Number"
TargetControlID="Zip">
</cc1:MaskedEditExtender>
<cc1:MaskedEditValidator
ID="ZipMaskExt"
runat="server"
ControlExtender="ZipMask"
ControlToValidate="Zip"
Display="None"
EmptyValueMessage="Field is required"
ErrorMessage="Invalid Zip Code"
SetFocusOnError="true"
IsValidEmpty="False"
ToolTip="Enter 9-digit Zip Code"
TooltipMessage="Enter 9-digit Zip Code"></cc1:MaskedEditValidator>
<asp:RegularExpressionValidator
ID="RegularExpressionValidator1"
runat="server"
ControlToValidate="Zip"
Display="None"
ErrorMessage="Zip Code must be 9-digits"
SetFocusOnError="True"
ValidationExpression="\d{5}(\d{4})?"></asp:RegularExpressionValidator>
<cc1:ValidatorCalloutExtender
ID="ValidatorCalloutExtender9"
runat="server"
TargetControlID="ZipMaskExt">
</cc1:ValidatorCalloutExtender>
<cc1:ValidatorCalloutExtender
ID="ValidatorCalloutExtender1"
runat="server"
TargetControlID="RegularExpressionValidator1">
</cc1:ValidatorCalloutExtender>
Thanks for the code example, but even closely matching your example with my code, the validation didn't work, regardless of what number combination I entered, which made me look more closely at my regex: (\d{3})[--.](\d{2})[--.](\d{4}). That seems to be
part of the problem, I whittled the regex down to \d{3}\d{2}\d{4} and that works (i.e. entering in nine digits validates).
I did run into some very odd behavior, though. Mona suggested I add the property ClearMaskOnLostFocus=True. That'd be a real nice property to add, but it won't work. At first, with that property in the MaskedEditExtender, the page wouldn't load at all. I
was getting an error in the BaseClassExtender.cs file (I'm pretty sure it was in that file) saying ClearMaskOnLostFocus isn't a property of MaskEditExtender. Problem is, I can't get that error to come back...
At any rate, as my code for the MaskedEditExtender is now, when I include the ClearMaskOnLostFocus property my validation "breaks", bringing me back to the point where nothing I enter in to the textbox will validate. Here's the current, working code:
One feature I know I'm going to need to get working in this text box is when the textbox loses focus I need the dashes in the SSN to stay. Currently, they don't, but, of course, before, when nothing else was working, the dashes did stay! Arrgh!
Any suggestions would be greatly appreciated!
Thanks
"f u cn rd ths, u cn gt a gd jb n cmptr prgmmng." - Anon
I don't know why you'd be getting that error because I was able to get the ClearMaskOnLostFocus to work. I had to play with the Validators to do so. See below for my updated code sample. I have an SSN field, Phone field and Zip+4 field all working correctly
with the MaskedEditExtender control. Basically, I had to replace the MaskedEditValidator with RegularExpressionValidator control to get it to work correctly. You might want to reconsider reinstalling the Ajax ToolKit and make sure you have the latest version.
Maybe there's something corrupt with your install?
capella07
Member
192 Points
273 Posts
Can't get MaskedEditExtender/Validator to work
Jul 12, 2007 03:29 PM|LINK
After about two hours of fiddling with it myself and searching the 'Net for anything that would help, I haven't run across anything that seems to help.
Here's my code:
<ajaxToolkit:MaskedEditExtender ID="editExtSSN" runat="server" TargetControlID="txtInsSSN" Mask="999-99-9999" MaskType="Number" MessageValidatorTip="True" ErrorTooltipEnabled="True" CultureName="en-US" /> <ajaxToolkit:MaskedEditValidator ID="editValidatorSSN" runat="server" ControlExtender="editExtSSN" ControlToValidate="txtInsSSN" ValidationExpression="\d{3}-\d{2}-\d{4}" InvalidValueMessage="Entry is invalid" IsValidEmpty="True" InvalidValueBlurredMessage="*" ValidationGroup="valSSN" Display="Dynamic" /> <asp:TextBox ID="txtInsSSN" runat="server" Width="160px" Font-Size="10px" ValidationGroup="SSN" />As you can see, I'm simply trying to allow only numbers to be entered in the textbos and validate for an SSN in the format ###-##-####. I've tried everything I can think of and my own social security number won't even validate! [:O]
I'd really appreciate it if someone can tell me what I'm doing wrong/missing!
Thanks...
bmains
All-Star
29116 Points
5886 Posts
MVP
Re: Can't get MaskedEditExtender/Validator to work
Jul 12, 2007 04:45 PM|LINK
Hey,
Your validation group on your MaskedEditValidator is different than your textbox.
"Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
capella07
Member
192 Points
273 Posts
Re: Can't get MaskedEditExtender/Validator to work
Jul 12, 2007 05:26 PM|LINK
Thanks for the reply, Brian.
While you were right in pointing that out, that oversight unfortunately didn't solve my problem...
Wierd thing is, I've got a date textbox with a maskededitextender/validator and calendarextender attached to it and that works just fine. [8-)]
I just "modeled" the ssn textbox after the date textbox, figuring if the one worked, then the other should. But noooo!
Here's the code for both:
<asp:TemplateField HeaderText="Hire Date"> <InsertItemTemplate> <ajaxToolkit:MaskedEditExtender ID="editExtHireDate" runat="server" TargetControlID="txtHireDate" Mask="99/99/9999" MaskType="Date" MessageValidatorTip="True" OnFocusCssClass="MaskedEditFocus" OnInvalidCssClass="MaskedEditError" ErrorTooltipEnabled="True" /> <ajaxToolkit:MaskedEditValidator ID="editValidatorHireDate" runat="server" ControlExtender="editExtHireDate" ControlToValidate="txtHireDate" IsValidEmpty="True" InvalidValueMessage="Date is invalid. Select a date from the calendar or enter the format mm\dd\yyyy." Display="Dynamic" InvalidValueBlurredMessage="*" ValidationGroup="valHireDate" ValidationExpression="(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d" /> <ajaxToolkit:CalendarExtender ID="calExtHireDate" runat="server" Enabled="True" TargetControlID="txtHireDate" Format="MM/dd/yyyy"> </ajaxToolkit:CalendarExtender> <asp:TextBox ID="txtHireDate" runat="server" Text='<%# Bind("HireDate") %>' Width="160px" Font-Size="10px" ValidationGroup="valHireDate" /> </InsertItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="SSN"> <InsertItemTemplate> <ajaxToolkit:MaskedEditExtender ID="editExtSSN" runat="server" TargetControlID="txtInsSSN" Mask="999-99-9999" MaskType="None" MessageValidatorTip="True" OnFocusCssClass="MaskedEditFocus" OnInvalidCssClass="MaskedEditError" ErrorTooltipEnabled="True" /> <ajaxToolkit:MaskedEditValidator ID="editValidatorSSN" runat="server" ControlExtender="editExtSSN" ControlToValidate="txtInsSSN" IsValidEmpty="True" InvalidValueMessage="Entry is invalid." Display="Dynamic" InvalidValueBlurredMessage="*" ValidationGroup="valSSN" ValidationExpression="(\d{3})[--.](\d{2})[--.](\d{4})" /> <asp:TextBox ID="txtInsSSN" runat="server" Width="160px" Font-Size="10px" ValidationGroup="valSSN" /> </InsertItemTemplate> </asp:TemplateField>Aside from the SSN textbox not being validated right, it also isn't keeping the dashes after the textbox loses focus. But the dashes return upon gaining focus again. I'm stumped...
HELP! [:O]
thecodedude
Member
54 Points
15 Posts
Re: Can't get MaskedEditExtender/Validator to work
Jul 13, 2007 01:27 AM|LINK
I have the same type of MaskedEdit control (i.e. SSN Input field) and mine works fine. The difference is I don't have the ValidationExpression and ValidationGroup on mine. I'd at least remove the ValidationExpression because it's unnecessary. :)
HTH,
Rick
capella07
Member
192 Points
273 Posts
Re: Can't get MaskedEditExtender/Validator to work
Jul 13, 2007 01:24 PM|LINK
Thanks for replying Rick, but unfortunately that didn't solve the problem either.
You say yours is the same except for the group and expression, but there's got to be something else going on that I'm overlooking.
Removing the validation group doesn't make a difference. I.e. it doesn't seem that it's needed here, but removing the validation expression allowed anything to go through, as long as it was a number - even less than nine digits. However, when "MaskType" is set to "Number", rather than "None" and I type in less than nine digits, when the textbox loses focus the rest of the spaces are filled in with zeros!
Could someone PLEASE explain to me what the heck is going on with this thing and hwo to get it to work the way I need it to!?!?!
Okay - yes, I'm a little frustrated...
thecodedude
Member
54 Points
15 Posts
Re: Can't get MaskedEditExtender/Validator to work
Jul 14, 2007 01:54 AM|LINK
OK....first of all to get rid of the zeros set AutoComplete=false. That way it won't fill in empty spaces. Second, I think I've got it to work but had to add a RegularExpressionValidator and another ValidationCalloutExtender (see below). I tested this and it works for me. [:)]
HTH,
Rick <asp:TextBox ID="Zip" runat="server"></asp:TextBox> <cc1:MaskedEditExtender ID="ZipMask" runat="server" AutoComplete="false" ErrorTooltipEnabled="true" InputDirection="LeftToRight" Mask="99999-9999" MaskType="Number" TargetControlID="Zip"> </cc1:MaskedEditExtender> <cc1:MaskedEditValidator ID="ZipMaskExt" runat="server" ControlExtender="ZipMask" ControlToValidate="Zip" Display="None" EmptyValueMessage="Field is required" ErrorMessage="Invalid Zip Code" SetFocusOnError="true" IsValidEmpty="False" ToolTip="Enter 9-digit Zip Code" TooltipMessage="Enter 9-digit Zip Code"></cc1:MaskedEditValidator> <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="Zip" Display="None" ErrorMessage="Zip Code must be 9-digits" SetFocusOnError="True" ValidationExpression="\d{5}(\d{4})?"></asp:RegularExpressionValidator> <cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtender9" runat="server" TargetControlID="ZipMaskExt"> </cc1:ValidatorCalloutExtender> <cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtender1" runat="server" TargetControlID="RegularExpressionValidator1"> </cc1:ValidatorCalloutExtender>Mona
Member
16 Points
11 Posts
Re: Can't get MaskedEditExtender/Validator to work
Jul 15, 2007 05:37 PM|LINK
Hi,
Add this in your MaskedEditExtender, it should solve your problem losing the mask:
ClearMaskOnLostFocus
=falsecapella07
Member
192 Points
273 Posts
Re: Can't get MaskedEditExtender/Validator to work
Jul 16, 2007 03:42 PM|LINK
Hey, Rick
Thanks for the code example, but even closely matching your example with my code, the validation didn't work, regardless of what number combination I entered, which made me look more closely at my regex: (\d{3})[--.](\d{2})[--.](\d{4}). That seems to be part of the problem, I whittled the regex down to \d{3}\d{2}\d{4} and that works (i.e. entering in nine digits validates).
I did run into some very odd behavior, though. Mona suggested I add the property ClearMaskOnLostFocus=True. That'd be a real nice property to add, but it won't work. At first, with that property in the MaskedEditExtender, the page wouldn't load at all. I was getting an error in the BaseClassExtender.cs file (I'm pretty sure it was in that file) saying ClearMaskOnLostFocus isn't a property of MaskEditExtender. Problem is, I can't get that error to come back...
At any rate, as my code for the MaskedEditExtender is now, when I include the ClearMaskOnLostFocus property my validation "breaks", bringing me back to the point where nothing I enter in to the textbox will validate. Here's the current, working code:
<asp:TemplateField HeaderText="SSN"> <InsertItemTemplate> <ajaxToolkit:MaskedEditExtender ID="editExtSSN" runat="server" TargetControlID="txtInsSSN" Mask="999-99-9999" MessageValidatorTip="True" InputDirection="LeftToRight" OnInvalidCssClass="MaskedEditError" ErrorTooltipEnabled="True" AutoComplete="False" /> <ajaxToolkit:MaskedEditValidator ID="editValidatorSSN" runat="server" ControlExtender="editExtSSN" ControlToValidate="txtInsSSN" IsValidEmpty="True" InvalidValueMessage="Entry is invalid" InvalidValueBlurredMessage="*" ValidationExpression="\d{3}\d{2}\d{4}" /> <asp:TextBox ID="txtInsSSN" runat="server" Width="160px" Font-Size="10px" /> </insertitemtemplate> </asp:TemplateField>One feature I know I'm going to need to get working in this text box is when the textbox loses focus I need the dashes in the SSN to stay. Currently, they don't, but, of course, before, when nothing else was working, the dashes did stay! Arrgh!
Any suggestions would be greatly appreciated!
Thanks
thecodedude
Member
54 Points
15 Posts
Re: Can't get MaskedEditExtender/Validator to work
Jul 17, 2007 02:17 AM|LINK
I don't know why you'd be getting that error because I was able to get the ClearMaskOnLostFocus to work. I had to play with the Validators to do so. See below for my updated code sample. I have an SSN field, Phone field and Zip+4 field all working correctly with the MaskedEditExtender control. Basically, I had to replace the MaskedEditValidator with RegularExpressionValidator control to get it to work correctly. You might want to reconsider reinstalling the Ajax ToolKit and make sure you have the latest version. Maybe there's something corrupt with your install?
HTH,
Rick
<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <label for="<%= Street.ClientID %>">Street:
</label> <asp:TextBox ID="Street" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="Street" Display="None" ErrorMessage="Street is required" SetFocusOnError="True"></asp:RequiredFieldValidator> <cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtender3" runat="server" TargetControlID="RequiredFieldValidator3"> </cc1:ValidatorCalloutExtender> <label for="<%= City.ClientID %>"> <br />City:
</label> <asp:TextBox ID="City" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="City" Display="None" ErrorMessage="City is required" SetFocusOnError="True"></asp:RequiredFieldValidator> <cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtender4" runat="server" TargetControlID="RequiredFieldValidator4"> </cc1:ValidatorCalloutExtender> <label for="<%= State.ClientID %>"> <br />State:
</label> <asp:TextBox ID="State" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="State" Display="None" ErrorMessage="State is required" SetFocusOnError="True"></asp:RequiredFieldValidator> <cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtender5" runat="server" TargetControlID="RequiredFieldValidator5"> </cc1:ValidatorCalloutExtender> <label for="<%= Zip.ClientID %>"> <br />Zip Code:
</label> <asp:TextBox ID="Zip" runat="server"></asp:TextBox> <cc1:MaskedEditExtender ID="ZipMask" runat="server" AutoComplete="false" ClearMaskOnLostFocus="false" ErrorTooltipEnabled="true" InputDirection="LeftToRight" Mask="99999-9999" MaskType="Number" TargetControlID="Zip"> </cc1:MaskedEditExtender> <asp:RegularExpressionValidator ID="ValidZip" runat="server" ControlToValidate="Zip" Display="None" ErrorMessage="Zip Code must be 9-digits" SetFocusOnError="True" ValidationExpression="\d{5}(-\d{4})?"></asp:RegularExpressionValidator> <cc1:ValidatorCalloutExtender ID="ValidZipExt" runat="server" TargetControlID="ValidZip"> </cc1:ValidatorCalloutExtender> <br /> <label for="<%= SSN.ClientID %>"> <br />SSN:
</label> <asp:TextBox ID="SSN" runat="server"></asp:TextBox> <cc1:MaskedEditExtender ID="SSNMask" runat="server" AutoComplete="false" ClearMaskOnLostFocus="false" ErrorTooltipEnabled="true" InputDirection="LeftToRight" Mask="999-99-9999" MaskType="Number" MessageValidatorTip="true" TargetControlID="SSN"> </cc1:MaskedEditExtender> <asp:RegularExpressionValidator ID="ValidSSN" runat="server" ControlToValidate="SSN" Display="None" ErrorMessage="SSN is Invalid" SetFocusOnError="True" ValidationExpression="\d{3}-\d{2}-\d{4}"></asp:RegularExpressionValidator> <cc1:ValidatorCalloutExtender ID="ValidSSNExt" runat="server" TargetControlID="ValidSSN"> </cc1:ValidatorCalloutExtender> <br /> <label for="<%= Phone.ClientID %>"> <br />Phone:
</label> <asp:TextBox ID="Phone" runat="server"></asp:TextBox> <cc1:MaskedEditExtender ID="PhoneMask" runat="server" AutoComplete="false" ClearMaskOnLostFocus="false" ErrorTooltipEnabled="true" InputDirection="LeftToRight" Mask="(999)999-9999" MaskType="Number" MessageValidatorTip="true" TargetControlID="Phone"> </cc1:MaskedEditExtender> <asp:RegularExpressionValidator ID="ValidPhoneNumber" runat="server" ControlToValidate="Phone" Display="None" ErrorMessage="Invalid Phone Number" SetFocusOnError="True" ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}"></asp:RegularExpressionValidator> <cc1:ValidatorCalloutExtender ID="PhoneMaskRequiredExt" runat="server" TargetControlID="ValidPhoneNumber"> </cc1:ValidatorCalloutExtender> <br /> <asp:Button ID="Button1" runat="server" Text="Submit" /> </ContentTemplate> </asp:UpdatePanel>capella07
Member
192 Points
273 Posts
Re: Can't get MaskedEditExtender/Validator to work
Jul 17, 2007 01:06 PM|LINK
Yeah, I'll take a good look at your code and compare/adjust mine.
Only thing is, again, what's the use of the MaskedEditValidator if the RegularExpressionValidator has to be used as well?
AJAX/MS gurus take note - maybe a bug/glitch has been found?
I guess it wouldn't hurt to reinstall Ajax as well - just to be sure...
Wish me luck!