mimimum / set length reqs for MaskedTextbox

2 posts, 0 answers
  1. Coty
    Coty avatar
    90 posts
    Member since:
    Aug 2006

    Posted 18 Nov 2008 Link to this post

    Looking to use the phone mask (###) ###-#### and set a valid values to be length of 7 or 10.

    I can use a regular expression validator on an ASP.NET control, but it does not work with the Masked TextBox.

    Any Ideas?

    Thanks,

    Coty

  2. Coty
    Coty avatar
    90 posts
    Member since:
    Aug 2006

    Posted 18 Nov 2008 Link to this post

    I figured out a way to do this in case anyone else comes along.  I used a custom validator with a ClientValidationFunction Set.
    Here is my code:

    HTML

     

     

     

    <rad:RadMaskedTextBox ID="txtTollFree" Mask="(###)###-####"   
                                    onblur="javascript:UpdatePreview('Phone');" Width="73px"   
                                    runat="server" BackColor="#CCCCCC" Enabled="False">  
                                </rad:RadMaskedTextBox> 
                                <asp:CustomValidator ID="CustomValidator1" runat="server"   
                                    ClientValidationFunction="CheckLength"   
                                    ErrorMessage="Phone\Fax numbers must be 7 or 9 digits" 
                                    ControlToValidate="txtTollFree">*</asp:CustomValidator> 

    Javascript

     

     

    function CheckLength(source, args)  
    {  
        if (args.Value.length == 10 || args.Value.length == 13)  
        {  
            args.IsValid = true;  
        }else{  
            args.IsValid = false;  
        }  

     

     


    Only hitch was I had to add 3 to the lengths I was checking for because of the mask ()- characters.

    Thanks,

    Coty

     

     

     

     

     

     

  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top