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

RegularExpressionValidator Doesn't Work WIth MaskedTextBox

1 Answer 78 Views
MaskedTextBox
This is a migrated thread and some comments may be shown as answers.
Holly
Top achievements
Rank 1
Holly asked on 23 Jul 2015, 07:47 PM

Hi.  I am trying to validate a MaskedTextBox in Asp.net using a RegularExpressionValidator control.  The validation works on a normal textbox, but I can't get it to work on the MaskedTextBox.  I'm getting the error message Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

 

Here is my code:

 

<telerik:RadMaskedTextBox ID="txtFederalTaxID" runat="server" Mask="##-#######" CssClass="field" SelectionOnFocus="SelectAll">
                                                        </telerik:RadMaskedTextBox>
                                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator28" runat="server" ErrorMessage="*" ControlToValidate="txtFederalTaxID" InitialValue="" ValidationGroup="Terms"></asp:RequiredFieldValidator>
                                                        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" ControlToValidate="txtFederalTaxID" runat="server" ValidationExpression="^(?!(\d)\1+$|(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)|9(?=0)){5}\d$|(?:0(?=9)|1(?=0)|2(?=1)|3(?=2)|4(?=3)|5(?=4)|6(?=5)|7(?=6)|8(?=7)|9(?=8)){5}\d$)\d{9}$" ErrorMessage="Invalid!" Width="20px"></asp:RegularExpressionValidator>
       

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 28 Jul 2015, 11:37 AM
Hi Holly,

I am not sure why you are receiving the error in question, but in a simplified project the code that you have provided does not throw an exception.

Nevertheless, if you need to validate the RadMaskedTextBox with a RegularExpressionValidator you could try to include the literals as well. In the context of your example, you could try to to include the "-" in the expression. Another option is to use CustomValidator and handle the validation manually.

On a side note, since the RadMaskedTextBox will validate the expression itself, you can use simple RequieredFieldValidator.

As for the exception, if the problem persists, please open regular support ticket with sample, runnable project attached, so we can test it locally.



Regards,
Konstantin Dikov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
MaskedTextBox
Asked by
Holly
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or