R – Is there pseudocode for UK address or phone number validation


Do you have pseudocode for field validation of the following items in the UK? I am from the USA, so I only know the ones in the USA right now.

  • Address Line 1
  • Phone Number
  • Mobile Number (in case they have a special rule for this, which they might not)
  • Post Code

Best Solution

Address line 1, if you want to validate what the user entered freeform, you're probably hosed. There's huge variability. You can use the PostCode Address File (see below) to assist,

Typically, if you want a "standard" address, UK-oriented websites ask for the postcode, then prompt the user to choose the correct address from all addresses at that postcode

Phone and mobile numbers. See here http://en.wikipedia.org/wiki/Telephone_numbers_in_the_United_Kingdom. A script to validate these (in several languages) can be found here: http://www.braemoor.co.uk/software/telnumbers.shtml

Post code format: http://en.wikipedia.org/wiki/UK_postcodes (contains a regular expression for validation, and refers to the Postcode Address File which lists valid addresses)