views:

449

answers:

6
+14  Q: 

i18n Validations

Think Global, Act Local

That's what they tell you, however during all my time as I developer I've always seen big companies like Google, Microsoft, Oracle and so do validations in a localized manner: they know which country I'm from so they will try to validate my phone number, postal code and other details such as bank account numbers with the proper validation methods for my country. Yesterday I signed up for Google checkout and they even showed me some examples of postal code formats in my country!

So my question is, how do they do this? I know that they have thousands of employees but I find it hard to believe that they all had to reinvent the well. There are countless validations methods for the US but what about the rest of the world? I've not yet seen a single open source decent library (apart from a very incomplete and outdated PEAR attempt) to perform validations on various common aspects of countries such as:

  • Civil ID
  • Tax ID
  • SSN (Social Security Number)
  • BBAN (Basic Bank Account Number)
  • Fax, Phone and Mobile Numbers
  • Postal / Zip Codes
  • License Plates
  • Banknote Serial Numbers
  • and so on...

Is there any well hidden resource that I'm unaware of?

A: 

Wikipedia collects license plate information, by country. Likewise for postal codes.

Martin v. Löwis
There is a lot more to validation than just license plates and postal codes, nonetheless UPU has much better resources (http://www.upu.int/post_code/en/postal_addressing_systems_member_countries.shtml) on postal code formats. Regarding the Wikipedia entry on license plates is very limited (only single pictures avaliable for 30 countries or so).
Alix Axel
+1  A: 

The PEAR one is not too bad. For example, the validator for New Zealand has all kinds of useful stuff like postal codes, IRD numbers, telephone numbers, bank account numbers http://pear.php.net/manual/en/package.validate.validate-nz.php

Its still in Alpha, but covers quite a few countries. Might be worth reconsidering?

Steve
I don't believe so, mainly because the validation methods for New Zealand (or any other country) are not coherent with other countries: Spain for instance only has DNI validation (civil ID) and Portugal (and many others) don't have any validation method. This is pretty much useless in a i18n environment IMO.
Alix Axel
Have you seen this? http://www.thomasweidner.com/flatpress/2009/09/19/zend_validate_postcode/
Steve
@Steve: That's very interesting, how can I have a peek into the code?
Alix Axel
A: 

Well , i think all it takes is one programmer from that country and a couple of days for reasearch & write the validations .. nothing special .. + there is tons of info in wikipedia

Aviatrix
That is exactly the point, I'm from Portugal and I can write a pretty good set of validation methods for my country but I don't know a thing about Spain for instance. Wikipedia is good, and I've done some nice work researching there but there is a lot missing.
Alix Axel
yeah .. but you can always ask some random person online .. right .. forums , stackoverflow .. etc .. it takes just about 2 braincells to figure it out :P
Aviatrix
Again, that's the point of this question if you read it carefully...
Alix Axel
A: 

Perhaps from http://www.geonames.org/ they have a wonderfull api too

+1  A: 

There's a huge difference between simple and full validation. It is often impossible to standardize validation fully across locales, here are a couple of examples:

  • CivilID/SSN etc. numbers can allow/disallow substitute values (system specific), foreign values, historic values etc. We have 2 different validation systems in one of our applications for the same field, depending on context, and other IT systems may have other validation systems.

  • ZIP code validation may require access to a list of valid values, which is something you need to subscribe to. In many countries, this subscription is not automated, and because of copyright rules, it is not trivial to redistribute.

  • Phone numbers have a similar problem. Do you allow expensive numbers, mobile phone numbers? How do you detect them?

You may argue that a simple validation is possible in most cases - but for simple validation, it is often easier to use pattern matching and to let the local department in each market define the valid patterns.

There is also a problem with the software service contract. If you buy software and want to use it for 5 years, then it is vital that you can change the validation rules, if something changes. I have experienced 4 changes of the phone number system in my country that affected simple validation like "number of digits" and "what can the first digit be".

Therefore, the best solution is to have a centralized database of locale-specific patterns, and to allow the administrators to modify the validation patterns.

Lars D
A: 

Maybe this is not a good place to discuss such things

Misier