Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4345084
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:59:14+00:00 2026-05-21T11:59:14+00:00

Greetings, I’m using a local copy of the Geonames database, including the country-info data.

  • 0

Greetings,

I’m using a local copy of the Geonames database, including the country-info data. My custom .NET application needs to validate the Postal/Zip codes that users input. The validation needs to be done locally and can not use the Geonames web services that are available. This is a requirement of my application. I’m hoping you can help me figure out how to do this.

Inside of the Geonames Country Info database there is a field that includes the regular expression to validate the Country/Zip code for the corresponding country. Here are the regular expressions that are contained in the data for both Canada and the USA:

Regexs in the Geonames database:

Canada: ^([a-zA-Z]d[a-zA-Z]d[a-zA-Z]d)$
USA: ^(d{9})$

In my application, once the validation is done I first identify the country that is selected and then I look up the valid postal code regex for the specific country. I then use the following .NET/C# code to test for a match:

bool testResult = Regex.IsMatch(postalCode, geonamesRegexForCountry);

When I enter valid sample data for the postal/zip codes, the regular expression match test always fails. Here are some valid values:

Canada:
   Postal Code: L5R3K6
   Postal Code: L8M1L5

USA:
   Zip Code: 35801
   Zip Code: 72201

The tests are always failing. Any idea why? Does the Geonames database use a different “regular expression syntax” than the .NET Regex.Match() function uses? Any suggestions on how to proceed from here?

I need to validate the postal/zip codes for all countries – not just Canada and the USA, so I’m really hoping I can leverage the wealth of content existing in the Geonames database!

Thanks for all of your help!

MomentSurfer

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T11:59:15+00:00Added an answer on May 21, 2026 at 11:59 am

    Perhaps it’s just a formatting problem, but there are backslashes missing in your regexes:

    Canada: ^([a-zA-Z]\d[a-zA-Z]\d[a-zA-Z]\d)$
    USA: ^(\d{9})$
    

    And, of course, they might not be matching your actual data. For example, the USA version only matches Zip codes like 123456789 (exactly 9 digits) but not 12345 or 12345-6789. And the Canada version likewise doesn’t allow for any separators between the characters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greetings, I'm using https://github.com/blueimp/jQuery-File-Upload (downloaded the version as of 5/21/2011) along with ASP.NET MVC3.
Greetings all, In my application,user can open several QWindows which share the same data.(save
Greetings Stackoverflow. I am currently using 000webhost.com as my MySQL database / server provider.
Greetings, Using this Query to extra data to CSV file from customized OS Commerce
Greetings all, I'm trying to localize a .NET/C# project. I'm using string resource files
Greetings, I am trying to run an SQL Script uploaded using Application Express (APEX),
Greetings! I have a Repeater control that's using an XmlDataSource control. <asp:FormView id=myFormView runat=server
Greetings. I've been using vim for years, and I've recently started toying with XCode.
Greetings all. I am writing some code using the Boost Units library and have
Greetings , I am a new developer in BlackBerry Application. I have been working

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.