Original code for Django localflavor UK telephone number forms.

Validates and cleans UK telephone numbers. Number length is checked, and numbers are cleaned into a common format. For example, "+44 (0)1234 567890" will be stored as "01234 567890".

Can reject premium numbers (09123 123123) or service numbers (1471, 118 118) with UKPhoneNumberField(reject=('premium', 'service')).
Initial commit of updated code for Django localflavor UK telephone number forms correcting a large number of errors.

Additional tests for tests/regressiontests/localflavor/uk/tests.py

Additional text for docs/refs/contribs/localflavor.txt

Validates and cleans UK telephone numbers. Number length is checked, and numbers are cleaned into a common format. For example, "+44 (0)1234 567890" will be stored as "01234 567890".

Can reject premium numbers (0912 312 3123) or service numbers (1471, 118 118) with UKPhoneNumberField(reject=('premium', 'service')).

Comparison with previous version:

(r'^01',                   None,     (5, (5, 6))),
misses the (6, 4) numbers in one area code
(r'^016977\d{4}$',         None,     (6, 4)),
and misses the (6, 5) numbers in 12 area codes
(r'^01(3873|5(242|39[456])|697[347]|768[347]|9467)', None, (6, 5)),

(r'^0[235]',               None,     (3, 4, 4)),
this should apply to 02x, 055 and 056 only
(r'^0(2[03489]|5[56])',    None,     (3, 4, 4)),
and 03xx numbers should be
(r'^03[0347]',             None,     (4, 3, 4)),

(r'^08',                   None,     (4, 7)),
the shorter (4, 6) 0800 numbers should be
(r'^0800\d{6}$',           None,     (4, 6)),
and the rest of the 08xx range should be
(r'^08[047]\d{8}$',        None,     (4, 3, 4)),

(r'^07',                   None,     (5, 6)),
should apply to 071 to 075, 07624, 077 to 079 only
(r'^07([1-57-9]|624)',     None,     (5, 6)),
and 070 numbers should be (3, 4, 4) and 'premium'
(r'^070',                 'premium', (3, 4, 4)),

(r'^(08001111|08454647)$', None,     (4, 4)),
no need to search for 08 twice, this simplifies to
(r'^08(001111|45464\d)$',  None,     (4, 4)),

(r'^09',                  'premium', (4, 6)),
is a digit short and should be split differently
(r'^09',                  'premium', (4, 3, 4)),

(r'^118',                 'service', (3, 3)),
should also cover 116 xxx too
(r'^11[68]',              'service', (3, 3)),
More detailed number range checking.

Validates and cleans UK telephone numbers. Number length is checked, and numbers are cleaned into a common format. For example, "+44 (0)1234 567890" will be stored as "01234 567890".

Can reject premium numbers (0912 312 3123) or service numbers (1471, 118 118) with UKPhoneNumberField(reject=('premium', 'service')).

Can reject multiple number types so you can tune the form input to accept only landline or only mobile, or whatever combination you want.

This version rejects individual invalid area codes and caters for area codes with mixed-length numbering in fine-grained detail.

Uses some of the RegEx patterns from:
http://www.aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_UK_Telephone_Numbers
Adds number type details for every number range. Additional error messages for unwanted number types. Additional tests.

Validates and cleans UK telephone numbers. Number length is checked, and numbers are cleaned into a common format. For example, "+44 (0)1234 567890" will be stored as "01234 567890".

Can reject premium numbers (0912 312 3123) or service numbers (1471, 118 118) with UKPhoneNumberField(reject=('premium', 'service')).

Can reject multiple number types so you can tune the form input to accept only landline or only mobile, or whatever combination you want.

This version rejects individual invalid area codes and number ranges and caters for area codes with mixed-length numbering in fine-grained detail.

Uses some of the RegEx patterns from:
http://www.aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_UK_Telephone_Numbers