NAME

Eircode - Validation and utilities for Eircodes / Irish postcodes

VERSION

version 0.1.0

SYNOPSIS

use Eircode qw< check_eircode >;

my $data = "not an eircode";

if( ! check_eircode($data) ){
   die 'Invalid';
}

DESCRIPTION

A module for checking Irish postcodes / Eircodes / éirchód.

EXPORTABLE

check_eircode

check_eircode("A65 B2CD") or die;

Checks it's first argument to see if it looks like a valid Eircode. If it does it returns a truthy value, if not it returns a falsey value.

A second argument, a hashref, can be provided to tweak the validation, these are all key => bool options.

strict => 1, # enforces upper case and the space mutually exclusive with lax
lax => 1, # allows any valid sequence irriguadless of spaces. mutually
          # exclusive with strict.

The default behaviour is to enforce the space but not case sensitivity.

So:

check_eircode("a65 b2cd"); # pass
check_eircode("a65b2cd", {lax => 1}); # pass
check_eircode("a65b2cd"); # fail
check_eircode("a65b2cd", {strict => 1}); # fail
check_eircode("a65 b2cd", {strict => 1}); # fail
check_eircode("A65 B2CD", {strict => 1}); # pass

normalise_eircode

say normalise_eircode("a65b2cd"); # Outputs A65 B2CD

Takes a loosely formatted eircode and formats it in upper case with the correct spacing. If the input doesn't look like a valid eircode will die with "invalid eircode".

split_eircode

my($routing_key, $uid) = split_eircode("a65 b2cd");
my($routing_key, $uid) = split_eircode("a65b2cd");

Take an eircode and gives you the two constitieent parts, the routing key and the uid.

VALIDATION NOTES

The validation doesn't check that the eircode is an existing code, merely that the formatting is correct, doesn't contain invalid characters etc. If you want to ensure the Eircode is a real existing code that goes well beyond the scope of what this module is trying to achieve. However you probably still want to run this kind of check before you go dialing out to an API to do that kind of check.

FUTURE

The checking is currently basic and there are no tools for dismembering an Eircode into it's parts or other such utilities which would seem to be useful here.

REFERENCES

https://en.wikipedia.org/wiki/Postal_addresses_in_the_Republic_of_Ireland https://www.eircode.ie/

CREDIT

Time to write this was provided by Print Evolved ltd, see http://www.printevolved.co.uk for all your print / print technology needs.

AUTHOR

Joe Higton <draxil@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2020 by Joe Higton <draxil@gmail.com>.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.