Skip to content

Commit

Permalink
Fixed Validity of UK postcodes (#814)
Browse files Browse the repository at this point in the history
  • Loading branch information
darkstego authored and stympy committed Feb 4, 2017
1 parent 098aa50 commit 3879812
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/locales/en-GB.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
en-GB:
faker:
address:
postcode: /[A-PR-UWYZ][A-HK-Y]?[0-9][ABEHMNPRVWXY0-9]? [0-9][ABD-HJLNP-UW-Z]{2}/
postcode: /[A-PR-UWYZ]([A-HK-Y][0-9][ABEHMNPRVWXY0-9]?|[0-9][ABCDEFGHJKPSTUW0-9]?) [0-9][ABD-HJLNP-UW-Z]{2}/
county: [Avon, Bedfordshire, Berkshire, Borders, Buckinghamshire, Cambridgeshire, Central, Cheshire, Cleveland, Clwyd, Cornwall, County Antrim, County Armagh, County Down, County Fermanagh, County Londonderry, County Tyrone, Cumbria, Derbyshire, Devon, Dorset, Dumfries and Galloway, Durham, Dyfed, East Sussex, Essex, Fife, Gloucestershire, Grampian, Greater Manchester, Gwent, Gwynedd County, Hampshire, Herefordshire, Hertfordshire, Highlands and Islands, Humberside, Isle of Wight, Kent, Lancashire, Leicestershire, Lincolnshire, Lothian, Merseyside, Mid Glamorgan, Norfolk, North Yorkshire, Northamptonshire, Northumberland, Nottinghamshire, Oxfordshire, Powys, Rutland, Shropshire, Somerset, South Glamorgan, South Yorkshire, Staffordshire, Strathclyde, Suffolk, Surrey, Tayside, Tyne and Wear, Warwickshire, West Glamorgan, West Midlands, West Sussex, West Yorkshire, Wiltshire, Worcestershire]
uk_country: [England, Scotland, Wales, Northern Ireland]
default_country: [England, Scotland, Wales, Northern Ireland]
Expand Down
8 changes: 8 additions & 0 deletions test/test_en_gb_locale.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,12 @@ def test_gb_postcode_incode_is_valid
incode = Faker::Address.postcode.split(' ')[1]
assert_match(/\d[ABDEFGHJLNPQRSTUWXYZ]{2}/, incode)
end

def test_gb_postcode_outcode_is_valid
outcode = Faker::Address.postcode.split(' ')[0]
assert_includes(2..4, outcode.length)
assert_match(/\w{1,2}\d{1,2}\w?/,outcode)
assert_match(/^[A-PR-UWYZ][A-HK-Y0-9]/,outcode)
assert_match(/\w{1,2}\d{1,2}|\w\d[ABCDEFGHJKPSTUW]|\w\w\d[ABEHMNPRVWXY]/,outcode)
end
end

0 comments on commit 3879812

Please sign in to comment.