I have a RadMaskedTextBox used for zip 5 or 9 data.
I would like to validate always for 5 digit zip code or 9 digit zip code.
the following regex does not catch zip code 33461-12 which is obviously wrong (it thinks its correct).
I think there is an issue with the underscores in the mask.
Valid zip codes should be:
33451
33545-1250
Anything else should be invalid, ex:
3314
33415-1
33145-12
33415-123
Any help would be greatly appreciated.
<telerik:RadMaskedTextBox ID="txtZipCode" runat="server" Mask="#####-####" SelectionOnFocus="CaretToBeginning"></telerik:RadMaskedTextBox>
<asp:RegularExpressionValidator
ID="RegularExpressionValidator1"
ControlToValidate="txtZipCode"
ValidationExpression="^((\d{5}(-|\s)\d{0,4})|(\d{5}))$"
ErrorMessage="Zip code must be numeric nnnnn or nnnnn-nnnn."
Display="dynamic"
RunAt="server"></asp:RegularExpressionValidator>
I would like to validate always for 5 digit zip code or 9 digit zip code.
the following regex does not catch zip code 33461-12 which is obviously wrong (it thinks its correct).
I think there is an issue with the underscores in the mask.
Valid zip codes should be:
33451
33545-1250
Anything else should be invalid, ex:
3314
33415-1
33145-12
33415-123
Any help would be greatly appreciated.
<telerik:RadMaskedTextBox ID="txtZipCode" runat="server" Mask="#####-####" SelectionOnFocus="CaretToBeginning"></telerik:RadMaskedTextBox>
<asp:RegularExpressionValidator
ID="RegularExpressionValidator1"
ControlToValidate="txtZipCode"
ValidationExpression="^((\d{5}(-|\s)\d{0,4})|(\d{5}))$"
ErrorMessage="Zip code must be numeric nnnnn or nnnnn-nnnn."
Display="dynamic"
RunAt="server"></asp:RegularExpressionValidator>