VAB Conditional validation rules - best practice?

Topics: Validation Application Block
Jan 8, 2009 at 8:35 PM
First let me clarify what I mean by conditional validation rules.

Address class has ZipCode property.

When the Country is set to US, zipcode field has validation criteria (5 digits or 5+4 digits, as in 90210 or 90210-0034)
When the Country is set to Canada, zipcode field has validation criteria (A#A #A#, where A = string letter and # = numeric digit, as in K2T 4G5)

A RegEx validator could be used to allow 1 or the other.  However this would not prevent you from adding a Canadian postal code when a US state was selected.  And for a globalized application that supports countries other than north america... I haven't even gotten to the details of that yet.

I have seen this thread which addresses the issue in one way, and also suggests another better way that could be implemented as part of the block, but I doubt that has been implemented yet.

Has anyone worked out the best way to handle this challenge?  Or is the above suggestion in the thread the best way to go?
Jan 9, 2009 at 1:07 AM
There's no direct support for this type of validation in EntLib.  The easiest way is still to use SelfValidation as mentioned in the thread.  Another alternative is to create your own validator.

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.