Validate countries telephone numbers

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ashishsoni
Forum Newbie
Posts: 1
Joined: Mon Feb 08, 2010 4:03 am

Validate countries telephone numbers

Post by ashishsoni »

Hi friends,

I want a solution that validate the telephone number formats for all countries. My client wants to validate phone number from all over country. I have few country formats but how can I validate all country formats.

Please reply ASAP if anyone faced the same issues or if anyone know any ready made tool/webservice.
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: Validate countries telephone numbers

Post by aravona »

This could get difficult as for example in England we have at least 5 different phone number styles / numbers for different purposes (01 numbers, 02 numbers (basically the same as 01 so probs could validate the same but is business only), 0800, 08000 - and then mobiles)

For the UK at least this may help :

uk phone number validation with regex

Not done this myself so not 100%

I'm not sure you'll get a standardised one for every country unless you forcibly don't allow spaces, dashes, brackets etc and try and get them all to conform. Though, if your validating the number (so no letters etc) are you also going to verify the number (so its real and not 01234 567890 ? )
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Validate countries telephone numbers

Post by papa »

Is it worth the effort?

Ok when writing an email address, but telephone number?
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: Validate countries telephone numbers

Post by aravona »

papa wrote:Is it worth the effort?

Ok when writing an email address, but telephone number?
Sometimes thats just what is needed (Though often its optional) Government sites require it if you're signing up to things here. I've even had to put in a passport number for an online game (Though silly system accepted * ;) )
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Validate countries telephone numbers

Post by papa »

aravona wrote:
papa wrote:Is it worth the effort?

Ok when writing an email address, but telephone number?
Sometimes thats just what is needed (Though often its optional) Government sites require it if you're signing up to things here. I've even had to put in a passport number for an online game (Though silly system accepted * ;) )
I can buy the argument for government sites and such but sometimes it's just overkill. For example when registering on a site that forces you to choose a state in the US you live in even though you live in Europe.. :P

Very accurate data.. Not :)
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: Validate countries telephone numbers

Post by aravona »

papa wrote:
I can buy the argument for government sites and such but sometimes it's just overkill. For example when registering on a site that forces you to choose a state in the US you live in even though you live in Europe.. :P

Very accurate data.. Not :)
I agree, its often more annoying than anything. I can understand using it for online shopping - sometimes if your delivery is going to need you to be in then they'd call and let you know.

However like I said in my first post. For England alone (not necessarily including phone number formats for Scotland, Wales and N.Ireland) You need to validate the number is 01 or 02 or 07 or 08 and pretty much nothing else. Then validate the area code (in the Uk thats 5 numbers) followed by 6 numbers and then if its an 0800 or 08000. To be honest, per country you've got you're work cut out.
Post Reply