diff --git a/src/apps/companies/apps/add-company/__test__/postcodeRegionLookup.test.js b/src/apps/companies/apps/add-company/__test__/postcodeRegionLookup.test.js index 9304d10a6fa..d56d223ea39 100644 --- a/src/apps/companies/apps/add-company/__test__/postcodeRegionLookup.test.js +++ b/src/apps/companies/apps/add-company/__test__/postcodeRegionLookup.test.js @@ -17,11 +17,13 @@ describe('Postcode to region mapping', () => { const invalidPostcode3 = 'A12' const invalidPostcode4 = undefined const invalidPostcode5 = null + const invalidPostcode6 = 'SW11' expect(mapPostcodeToRegion(invalidPostcode1)).to.equal('') expect(mapPostcodeToRegion(invalidPostcode2)).to.equal('') expect(mapPostcodeToRegion(invalidPostcode3)).to.equal('') expect(mapPostcodeToRegion(invalidPostcode4)).to.equal('') expect(mapPostcodeToRegion(invalidPostcode5)).to.equal('') + expect(mapPostcodeToRegion(invalidPostcode6)).to.equal('') }) }) diff --git a/src/apps/companies/apps/add-company/client/transformer.js b/src/apps/companies/apps/add-company/client/transformer.js index 7f8e739492e..3e877a8b556 100644 --- a/src/apps/companies/apps/add-company/client/transformer.js +++ b/src/apps/companies/apps/add-company/client/transformer.js @@ -146,7 +146,11 @@ export const mapPostcodeToRegion = (postcode) => { ) { return postcode } - const area = outcode.split(outcode.match(/\d+/)[0])[0] + const numericMatch = outcode.match(/\d+/) + if (!numericMatch) { + return '' + } + const area = outcode.split(numericMatch[0])[0] return POSTCODE_AREA_TO_REGION[area] } }