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

RadMaskedTextBox validation

5 Answers 438 Views
Input
This is a migrated thread and some comments may be shown as answers.
EkoEvolution
Top achievements
Rank 1
EkoEvolution asked on 09 Oct 2007, 06:54 PM
I am trying to use a RegularExpressionValidator on a RadMaskedTextBox that is collecting a US Zip Code. I am using the following properties:

Mask="#####-#####"
DisplayMask="#########"
DisplayPromptChar=""
SelectionOnFocus="CaretToBeginning"
ResetCaretOnFocus="true"

My RegularExpression is ^((\d{5}(-|\s)\d{4})|(\d{5})$

This fails for 32608 but works for 32608-0000 when using RadMaskedTextBox

The regular expression works when I do not use a RadMaskedTextBox and fails when I do. I read that the RadInput validates against a stripped version of the Text which should validate both 32608 and 32608-0000.

5 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 12 Oct 2007, 10:53 AM
Hello,

Indeed, with the regular expression that you have used, only expressions like 32608-0000  will be accepted. Another alternative would be to use client side script, to add 0's when the user only enters the first five digits. This can be done in the onBlur event on the client. Yet another approach is to change the regular expression, to allow 0-4, or 5 characters in the second sequence:

.aspx
<asp:RegularExpressionValidator runat="server" ID="RegularExpressionValidator1" 
 ValidationExpression="^((\d{5}(-|\s)\d{0,4})|(\d{5}))$"   
 ControlToValidate="RadMaskedTextBox1" 
 ErrorMessage="Incorrect Format!!!">  
</asp:RegularExpressionValidator> 

I hope this information helps.

Best wishes,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
plamen
Top achievements
Rank 1
answered on 24 Oct 2008, 12:07 PM
Hi,

You can review this blog post

Regards...
<John:Peel />
0
Murugavel B
Top achievements
Rank 1
answered on 29 May 2010, 01:42 PM
Is it fixed?
0
Yavor
Telerik team
answered on 03 Jun 2010, 07:40 AM
Hello Murugavel B,

Presently, the behavior is the same as explained initially. No modifications have been introduced to this functionality. Nevertheless, you can use the regular expression option, or the client script approach to handle the setup.

Kind regards,
Yavor
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
0
Atlas
Top achievements
Rank 1
answered on 31 Aug 2010, 11:42 PM
The validation expression that Telerik didn't work for me, but this did:
<asp:RegularExpressionValidator ValidationExpression="^((\d{5}-_{0,4})|(|(\d{5}-\d{4})))$" ID="RegularExpressionValidator6"
    ValidationGroup="vgBrokerApplication" runat="server" Display="None" ErrorMessage=" Invalid zip code "
    ControlToValidate="rmtbZip" />
Tags
Input
Asked by
EkoEvolution
Top achievements
Rank 1
Answers by
Yavor
Telerik team
plamen
Top achievements
Rank 1
Murugavel B
Top achievements
Rank 1
Atlas
Top achievements
Rank 1
Share this question
or