Skip to content

Instantly share code, notes, and snippets.

@peteeveleigh
Created March 17, 2022 10:59
Show Gist options
  • Select an option

  • Save peteeveleigh/1b15442fa8cc5045824ddcea87dc805b to your computer and use it in GitHub Desktop.

Select an option

Save peteeveleigh/1b15442fa8cc5045824ddcea87dc805b to your computer and use it in GitHub Desktop.

Revisions

  1. peteeveleigh created this gist Mar 17, 2022.
    19 changes: 19 additions & 0 deletions postcodeCheck.twig
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    {# These are the valid UK postcode formats
    according to https://ideal-postcodes.co.uk/guides/uk-postcode-format #}

    {% set zipCodes = [
    'AA9A 9AA',
    'A9A 9AA',
    'A9 9AA',
    'A99 9AA',
    'AA9 9AA',
    'AA99 9AA'
    ] %}



    {% for zipCode in zipCodes %}
    {# Normalise zipcode, remove spaces, make uppercase
    Remove last 3 characters and return the remainder #}
    {{ zipCode }} - {{ zipCode|replace({' ':''})|upper|slice(0,-3) }}
    {% endfor %}