チーズパン
チーズパン

Reputation: 2778

How to include a conditional check in my RegularExpressionValidator?

I have a asp:TextBox which is bound to a asp:RegularExpressionValidator. The ValidationExpression

ValidationExpression="\d{5}|\d{4}"

checks whether the input has a length of 4 or 5 digits. Those are supposed to be european zipcodes.

Now I also have a dropdown where the user can select her/his country.

What I want to achive is a conditional validation. So if the chosen country is Germany allow only zipcodes with a length of 5, otherwise lenght of 4 digits.

Is there a way to achieve this?

Upvotes: 1

Views: 489

Answers (1)

h3n
h3n

Reputation: 898

you can try to change the ValidationExpression at runtime according to this question. When the user selects germany you call

ValidationExpression = "\d{5}"

otherwise you call

ValidationExpression = "\d{4}"

Upvotes: 1

Related Questions