** I'm looking for a procedure that will format a string of numbers as a UK phone number. **
You can download the Ofcom database, which lists the formats for each range of numbers, including national number numbers, and searches for each number that needs to be formatted. The database lists SABCDE digits and format: 0 + 10, 2 + 8, 3 + 7, 4 + 6, 4 + 5, 5 + 5 or 5 + 4 for each range.
There are a small number of errors in the database (especially for 01697 and 0169 77 codes), but they contain less than ten errors in more than a quarter of a million entries.
There are four files covering numbers 01 and 02, and separate files for different ranges of non-geographical numbers.
0 + 10 numbers are "National Dialing Only" and are written without parentheses around part of the area code. The area code will be 02x for all numbers 02, 01xx for all numbers 011x and 01x1, and 01xxx for most other numbers 01 (a very small number - about ten - will be 01xx xx).
Parentheses surround the area code for all other numbers 01 and 02 (that is, use parentheses to numbers 01 and 02, where part of the local number does not start with 0 or 1). The brackets show that local dialing is possible within the same area, omitting the numbers enclosed in parentheses.
The nomenclature 2 + 8 shows the area code and the length of the local number, and the entry 2075: 2 + 8 means that the number is formatted as (020) 75xx xxxx. Remember that the leading zero is not “counted” in the definition of 2 + 8.
** UK phone numbers vary in length from 8 digits to 12 digits **
No. Since 2000, most of them have 10 digits after the code "0". Some of them still have 9 digits after the trunk code "0".
There are also several special rooms, such as 0800 1111 and 0845 4647.
Codes
** "area" can vary from 2 to 4 digits. **
Area codes can vary from 2 to 5 digits (leading zero is not counted). To be clear, “020” is classified as a 2-digit area code, because the leading 0 is actually a trunk code. There are also area codes 011x and 01x1, and most other numbers have area codes 01xxx. The latter can have local numbers, the length of which is only 5 digits instead of the more widely used 6-digit local numbers. A very small number has an area code of 01xx xx and they have 5 or 4 digit local numbers.
** Also, there is no standard for where spaces will be placed. **
Between the area code part and the local number part there is always a space for all numbers 01 and 02.
Traditionally, for area codes (01xxxx), there is a space inside the area code, as shown in the figure. This represents the old local exchange groups in which this system is still used. Other (shorter) area codes are not separated.
Local numbers with 7 or 8 digits are divided up to the fourth digit from the end. Local numbers with 4, 5 or 6 digits are not divided. This also applies to geographic and non-geographic numbers.
For most numbers 03, 08 and 09, the number is written as 0xxx xxx xxxx.
Some 0800 and all 0500 numbers are written 0xxx xxxxxx.
For numbers 055, 056 and 070, the number is recorded 0xx xxxx xxxx.
For mobile phones and pager numbers, use 07xxx xxxxxx.
** except that some use '08000 abc def' instead of '0800 0abc def' **
This is a misuse. Keep in mind that some 0800 numbers have 9 digits after the trunk code 0, while others have 10 digits after the trunk code.
Thus, both 0800 xxxxxx and 0800 xxx xxxx are correct.
0500 numbers use only 0500 xxxxxx.
Most of the numbers 03, 08 and 09 are written as 0xxx xxx xxxx.
See also: http://en.wikipedia.org/wiki/Local_conventions_for_writing_telephone_numbers#United_Kingdom