.netvalidationzipcodepostal-code

How can I validate worldwide postal codes in my .NET code


I am looking for a way to validate worldwide postal codes in my .NET project, and I don't really want to come up and maintain regular expressions for the whole world.

Preferably I would want to pull in a dependency to a library or in the worst case use some web based service (but that would really be a last resort).


Solution

  • Check out PostalCodes.Net package on github.

    It support most countries and has a good interface. Here is an example:

    var country = CountryFactory.Instance.CreateCountry("PL");
    var postalCode = PostalCodeFactory.Instance.CreatePostalCode(country, "44-100");