This is a migrated thread and some comments may be shown as answers.

mimimum / set length reqs for MaskedTextbox

1 Answer 57 Views
Input
This is a migrated thread and some comments may be shown as answers.
Coty
Top achievements
Rank 1
Coty asked on 18 Nov 2008, 08:27 PM
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

1 Answer, 1 is accepted

Sort by
0
Coty
Top achievements
Rank 1
answered on 18 Nov 2008, 09:22 PM
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

 

 

 

 

 

 

Tags
Input
Asked by
Coty
Top achievements
Rank 1
Answers by
Coty
Top achievements
Rank 1
Share this question
or