Get inward and outward codes from UK postal code

Viewed 1760

I'm trying to find a way to split a UK postcode from the user entry. The initial entry is validated by the below regex and it's working fine.

var regex = @"^([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([AZa-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z]))))[0-9][A-Za-z]{2})$";

Now I need to split the postcode into outward and inward codes so that I can send them separately to the client's ERP to get the shipping cost.

Example.

User input: DD81UN
Desired output: DD8 1UN

User input: DN551PT
Desired output: DN55 1PT

2 Answers
Related