[thelist] Validating Irish Phone Numbers

Keith Gaughan keith at digital-crew.com
Thu Dec 9 09:27:22 CST 2004


James Hardy wrote:

> Argh, and there was I hoping for some semblance of sanity.

Not a chance of that, I'm afraid. Maybe some time in the future, but not
yet. :-(

> Unfortunately I don't really want to do a full routine, while we are 
> only covering the two nations at the moment, We will probably be doing 
> more and I don't fancy doing 200 odd functions. So unless it all becomes 
> too much, I will stick with a regex for each number format.

Actually, it wouldn't be so bad. If your number validator was
data-driven, it'd be just a simple rules engine that would check the
number you pass in against a set of rules you've given it specifying
valid number patterns.

> From what you are saying I think /0[1-9][0-9]{5,9}/ would include all 
> valid numbers (I know it would include many many invalid ones but at the 
> moment I am doing no validation at all for Irish numbers and I would 
> accept "rhubarb" as a legit number. So any validation is better than 
> none). Is that right?

Better, though still not perfect but more accurate, would be:

     /0(1|[2-8]\d|9\d\d)[1-9]\d{4,6}/

where \d is equivalent to [0-9]. That should be sufficient for the
mobile phone numbers too.

-- 
Keith Gaughan, Developer
Digital Crew Ltd., Pembroke House, Pembroke Street, Cork, Ireland
http://digital-crew.com/


More information about the thelist mailing list