Tags: ajax, aspnet, conjunction, expression, figure, folks, maskededitextender, maskededitvalidator, net, validation

MaskedEditExtender with MaskedEditValidator

On .Net » ASP.NET AJAX

25,820 words with 14 Comments; publish: Sun, 06 Jan 2008 01:36:00 GMT; (1004,562.50, « »)

Hi Folks,

I'm new to Ajax and I'm trying to figure out if I can use the MaskedEditValidator "Validation Expression" in conjunction with the the MaskedEditExtender "Mask". I'm trying to apply the mask(999)999-9999 (which works fine), but at the same time I want to use the MaskedEditValidator "ValidationExpression" to limit the first character of the area code to 2-9. This does not seem to work. Any help would be greatly appreciated. Here's my code:

<cc1:MaskedEditExtenderID="MaskedEditExtender1"

runat="server"

TargetControlID="txtClientLookupValue"Mask="(999)999-9999"ClearMaskOnLostFocus="false">

</

cc1:MaskedEditExtender>

<

cc1:MaskedEditValidatorID="MaskedEditValidator1"ControlExtender="MaskedEditExtender1"runat="server"ControlToValidate="txtClientLookupValue"IsValidEmpty="True"ValidationExpression="^[2-9]\d{2}-\d{3}-\d{4}$"Display="Dynamic">

</

cc1:MaskedEditValidator>

Thank you,

Alan

All Comments

Leave a comment...

  • 14 Comments
    • Hi,

      Because the propertyClearMaskOnLostFocus="false" No Matches found, Your Regular expression is wrong, try it :

      ^\([2-9]\d{2}\)\d{3}-\d{4}$

      Thanks,

      #1; Sun, 06 Jan 2008 01:37:00 GMT
    • Hi - thanks for the reply. I tried the above expression, but I'm still getting an error when I tab out of the textbox. This error is from the "InvalidValueMessage" parameter of the MaskedEditValidator. I'm starting to wonder if the validator is conflicting with the mask in some way. I'll keep trying and if I figure it out, I will post. Here is my latest (updated) code.

      <cc1:MaskedEditExtender ID="MaskedEditExtender1"

      runat="server"

      TargetControlID="txtClientLookupValue"

      Mask="(999)999-9999"

      ClearMaskOnLostFocus="false">

      </cc1:MaskedEditExtender

      <%-- Mask="\(?\)???"--%>

      <cc1:MaskedEditValidator ID="MaskedEditValidator1"

      ControlExtender="MaskedEditExtender1"

      runat="server"

      ControlToValidate="txtClientLookupValue"

      IsValidEmpty="True"

      InvalidValueMessage="INVALID"

      ValidationExpression="^\([2-9]\d{2}\)\d{3}-\d{4}$"

      Display="Dynamic">

      </cc1:MaskedEditValidator>

      Thanks,

      Alan

      #2; Sun, 06 Jan 2008 01:38:00 GMT
    • PS. The following mask works with no parens. As soon as I add the parens to the mask. I get an error. Having the dash in the mask works fine.

      <cc1:MaskedEditExtender ID="MaskedEditExtender1"

      runat="server"

      TargetControlID="txtClientLookupValue"

      Display="Dynamic">

      </cc1:MaskedEditValidator>

      #3; Sun, 06 Jan 2008 01:39:00 GMT
    • Unfortunately I was not able to get this to work regardless of the ValidationExpression used. The phone mask that I used - (999)999-9999 worked correctly, but when I attempted to use the MaskedEditValidator, the validator always determined that the input was incorrect even though it was correct. Here is the last code snippet that I used that did not work. It appears as if the parens are the problem. Even if they are escaped, they still prevent the validator from seeing the input as correct. The validator works fine if there are no parens. Could this be a bug?? If anyone can find anything wrong with this, please post.

      <

      cc1:MaskedEditExtenderID="MaskedEditExtender1"runat="server"TargetControlID="txtClientLookupValue"Mask="(999)999-9999"ClearMaskOnLostFocus="false">

      </

      cc1:MaskedEditExtender>

      <cc1:MaskedEditValidatorID="MaskedEditValidator1"

      ControlExtender="MaskedEditExtender1"

      runat="server"ControlToValidate="txtClientLookupValue"IsValidEmpty="True"InvalidValueMessage="INVALID"ValidationExpression="^\([2-9]\d{2}\)\d{3}-\d{4}$"Display="Dynamic">

      </

      cc1:MaskedEditValidator>

      Thanks,

      Alan

      #4; Sun, 06 Jan 2008 01:40:00 GMT
    • Hi Alan,

      I found the problem. This is a bug.

      Workarround even I to publish the modifications in codeplex :

      at change Set (19494)

      File MaskedEditValidator.js

      ------------

      at lines 80,222, 411, 573 replace

      var mask = target.value.substring(parseInt(value.FirstMaskPosition,10),parseInt(value.LastMaskPosition,10));

      to

      var mask = target.value;

      File MaskedEditValidator.cs

      -------------

      replace

      ScriptManager.RegisterExpandoAttribute(this,this.ClientID,"ValidationExpression",this.ValidationExpression,false);

      to

      ScriptManager.RegisterExpandoAttribute(this,this.ClientID,"ValidationExpression",this.ValidationExpression, ClearMaskOnLostFocus="false">

      </ajaxToolkit:MaskedEditExtender>

      <ajaxToolkit:MaskedEditValidator ID="MaskedEditValidator11"

      ControlExtender="MaskedEditExtender11"

      runat="server"

      ControlToValidate="txtClientLookupValue"

      IsValidEmpty="True"

      InvalidValueMessage="INVALID"

      Display="Dynamic">

      </ajaxToolkit:MaskedEditValidator

      Thanks for you feedback!

      #5; Sun, 06 Jan 2008 01:41:00 GMT
    • I am having problem to fix the bug, what is the fast and easy way ?

      #6; Sun, 06 Jan 2008 01:42:00 GMT
    • FCerqueira wroteMar 27 at 1:49 PM

      Resolved with changeset 20497.

      FCerqueira wroteMar 26 at 9:16 PM

      Fixed at Change Set 19494
      Dude, I just downloaded the code and replaced the files in my MaskedEdit folder in my toolkit, this fix is either not working or I'm missing something here. Can you give us exact instructions on what to do here or recheck your "fix"?
      #7; Sun, 06 Jan 2008 01:43:00 GMT
    • That changeset does NOT fix the bug....

      #8; Sun, 06 Jan 2008 01:44:00 GMT
    • Any solution about it, mister ?

      Thanks.

      #9; Sun, 06 Jan 2008 01:45:00 GMT
    • I'll add my two cents here for a request to get this fixed as well!

      I also am trying to validate a phone number with parenthesis (which appears to be the culprit for the false positive in the validation error).

      I have made sure I'm using version 60618, which apparently is that didn't fix it.

      It'd be nice if someone could look into this (or point me to a fix, if one has been issued in the past 20 days since the last post in this thread!).

      #10; Sun, 06 Jan 2008 01:46:00 GMT
    • Mister Capella, any sample code, please ?

      Thanks in advance, greetings !!!!

      #11; Sun, 06 Jan 2008 01:47:00 GMT
    • Sure, alhambraeidos! Here you go:

      <asp:TemplateField HeaderText="Phone Number"><InsertItemTemplate><asp:TextBox ID="txtInsPhone" Runat="Server" Text='<%# Bind("Phone")%>' /><ajaxToolkit:MaskedEditExtender ID="maskPhone" Runat="Server" AutoComplete="False" TargetControlID="txtInsPhone" Mask="(999) 999-9999" MaskType="Number" InputDirection="LeftToRight" MessageValidatorTip="True" OnFocusCssClass="MaskedEditFocus" OnInvalidCssClass="MaskedEditError" ErrorTooltipEnabled="True" ClearMaskOnLostFocus="False" /><ajaxToolkit:MaskedEditValidator ID="editValidatorPhone" Runat="Server" ControlExtender="maskPhone" ControlToValidate="txtInsPhone" IsValidEmpty="True" InvalidValueMessage="Invalid entry. Please enter the phone number in the format "(###) ###-####"" Display="Dynamic" InvalidValueBlurredMessage="Error" ValidationExpression="\(\d{3}\)\s\d{3}\-\d{4}" /></InsertItemTemplate></asp:TemplateField>

      It may be worth noting that this templatefield is in a DetailsView, which is in a CollapseablePanel, which is in a TabPanel.

      Thanks for taking a look!

      #12; Sun, 06 Jan 2008 01:48:00 GMT
    • Well, I thought I'd give this problem a rest with the hopes that in the interim an actual working fix would show up. As soon as I saw that version 10920 of the Control Toolkit was released I updated to that hoping that there was a fix included there.

      Well, I wouldn't be posting here if it workaround? Or am I just simply doing something wrong?

      Anyone?...

      #13; Sun, 06 Jan 2008 01:49:00 GMT
    • Hi all,

      I'm having the same problem with the latest Toolkit and I also am getting the same error without the ( ) for the area code.

      The code below has 2 textboxes with a extender mask / validator

      <%.net-ajax.questionfor.info.RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit"TagPrefix="cc1" %>

      <!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

      <htmlxmlns="http://www.w3.org/1999/xhtml">

      <headrunat="server">

      <title>Untitled Page</title>

      </head>

      <body>

      <formid="form1"runat="server">

      <div>

      <asp:ScriptManagerID="ScriptManager1"runat="server">

      </asp:ScriptManager>

      <asp:TextBoxID="txtInsPhone"Runat="Server"Text='<%# Bind("Phone") %>'/>

      <br/>

      <br/>

      <cc1:MaskedEditExtenderID="maskPhone"Runat="Server"

      AutoComplete="False"

      TargetControlID="txtInsPhone"

      Mask="(999) 999-9999"

      MaskType="Number"

      InputDirection="LeftToRight"

      MessageValidatorTip="True"

      OnFocusCssClass="MaskedEditFocus"

      OnInvalidCssClass="MaskedEditError"

      ErrorTooltipEnabled="True"

      ClearMaskOnLostFocus="False"/>

      <cc1:MaskedEditValidatorID="editValidatorPhone"Runat="Server"

      ControlExtender="maskPhone"

      ControlToValidate="txtInsPhone"

      IsValidEmpty="True"

      InvalidValueMessage="Invalid entry. Please enter the phone number in the format (###) ###-####"

      Display="Dynamic"

      InvalidValueBlurredMessage="Error"

      ValidationExpression="\(\d{3}\)\s\d{3}\-\d{4}"/>

      </div>

      <br/>

      <asp:TextBoxID="txtInsPhone2"Runat="Server"Text=""/>

      <br/>

      <br/>

      <cc1:MaskedEditExtenderID="MaskedEditExtender1"Runat="Server"

      AutoComplete="False"

      TargetControlID="txtInsPhone2"

      Mask="999 999-9999"

      MaskType="Number"

      InputDirection="LeftToRight"

      MessageValidatorTip="True"

      OnFocusCssClass="MaskedEditFocus"

      OnInvalidCssClass="MaskedEditError"

      ErrorTooltipEnabled="True"

      ClearMaskOnLostFocus="False"/>

      <cc1:MaskedEditValidatorID="MaskedEditValidator1"Runat="Server"

      ControlExtender="MaskedEditExtender1"

      ControlToValidate="txtInsPhone2"

      IsValidEmpty="True"

      InvalidValueMessage="Invalid entry. Please enter the phone number in the format ### ###-####"

      Display="Dynamic"

      InvalidValueBlurredMessage="Error"

      ValidationExpression="\d{3}\s\d{3}\-\d{4}"/>

      </form>

      </body>

      </html>

      Thanks, LA Guy

      #14; Sun, 06 Jan 2008 01:50:00 GMT