views:

1752

answers:

5

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
+3  A: 

Address line 1 could be almost anything. There aren't always house numbers.

Phone numbers: the length of an area code varies. I wouldn't like to swear whether the full length is constant, but I suspect it's always at least 10 digits. Mobile numbers typically (IME) start with 07 whereas landlines typeically start with 01 or 02. Special numbers (free, local rate etc) typically start with 08. I'll try to find a reference for this. (EDIT: Again, there's a good Wikipedia article.)

Wikipedia has a good article about UK postcodes, including regular expressions for them.

Jon Skeet
"I wouldn't like to swear whether the full length is constant"it isn't. I often get told my home number is missing a digit when I give it over the phone. It isn't. :)
Paul
+4  A: 

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)

Paul
+2  A: 

Perl has the Number::Phone module that can handle UK phone numbers. Royal Mail has services for address validation and list cleansing.

brian d foy
+1  A: 

For UK phone numbers, your best bet (unfortunately) is probably to download the numbering plans from Ofcom (they're excel spreadsheets, with all relevant number ranges, split up into area codes, "geographical numbers", personal numbers, mobile numbers, assorted service numbers, the different pay-for numbers and also have a mapping from number range to operator (the latter is probably NOT something you need, though).

Vatine
+1  A: 

As always with this sort of question, don't get hung up on over-validation. Check for the most likely grossly-malformed inputs then move on. Trying to keep track of what prefixes and lengths of phone number are in use in any particular locale is an enormous waste of your time. Letting a few, possibly-fixable mistakes through is better than losing customers by telling them they are ‘invalid’.

(The nearest to a standard addressing format you get in the UK is postcode plus house number. Even then there are always exceptions. )

bobince