asp.net Validation: ZIP from Germany, Switzerland and Austria
I have a TextBox for the ZIP and a ComboBox for the country (sel开发者_开发知识库ectable: germany, switzerland and austria).
I am not much familiar with RegEx, I get it to build a simple one for ZIP of germany, but how to build one for allowed ZIPs of germany, switzerland and austria?
You should mention what rules the ZIP codes follow. A quick peek tells me they have 4 (Switzerland, Austria) or 5 (Germany) numbers.
/^\d{4,5}$/
would match that. If you want a more specific answer, then be more specific in your post.
Look in to Globalization, you can put the regex in a resource file and tell the validator to use it for the current culture. This way if the user is German it will use the German Resource File that uses the German way of validating Zip Code.
Check this tutorial out on Building Multilingual Web Sites, there are examples of how you localize validation.
Edit
I might have missunderstood the question a bit, if you want a regex that will pass on all the different zip-codes from German, Austria and Swizz, you can do what Ward Muylaert said. But it's better if you split the validation up so that you validate against the correct culture.
精彩评论