
Number::Phone::Normalize - Normalizes format of Phone Numbers.

use Number::Phone::Normalize;
print phone_intl('+1 (555) 123 4567'); # +1 555 1234567
print phone_local('+49-89-99999999','CountryCode'=>'49'); # 089 99999999

This module takes a phone (or E.164) number in different input formats and outputs it in accordance to E.123 or in local formats.

Normalizes the phone number $number and returns it in international (E.164) format. $number can be in an international format or in a local format if the CountryCode/AreaCode parameters are supplied.
If phone_intl does not have enough information to build an international number (e.g. neither $number does not contain a country code and %param does not specify a default), it returns undef.
Normalizes the phone number $number and returns it in local format. $number can be in an international format or in a local format if the CountryCode/AreaCode parameters are supplied.
If phone_local does not have enough information to build an international number (e.g. neither $number does not contain a country code and %param does not specify a default), it returns undef.
$numberThese parameters specify how the input $number is interpreted if it is in a non-international format.
CountryCodeThe local country code. It is added to phone numbers in local format without an country code.
AreaCodeThe local area code. It is added to phone numbers in local format without an area code.
IntlPrefixThe international prefix. If $number starts with this prefix, the country code and area code are taken from the number.
The default is '00' (ITU recommendation).
LDPrefixThe long distance prefix. If $number starts with this prefix, the area code is taken from $number and the country code is taken from the CountryCode parameter.
If $number starts with neither IntlPrefix nor LDPrefix, it is assumed to be in local format and both country and area codes are taken from the parameters.
The default is '0' (ITU recommendation).
These parameters specify how the output is formatted. Most parameters only have an effect on output in local format.
The local country code. If the number does not have the CountryCode specified, it is returned starting with the IntlPrefix.
The local country code. If the number does not have the CountryCode specified, it is returned starting with the LDPrefix.
IntlPrefixOutThe international prefix for output. If the number is not in the country specified by CountryCode, the returned number will start with this prefix.
The default is IntlPrefix.
You can set this parameter to '+' in order to return numbers in international format instead of the local format.
LDPrefixOutThe long distance prefix for output. It the number is not in the area specified by AreaCode or AlwaysLD is set to true, it is returned starting with LDPrefixOut.
The default is LDPrefix.
AlwaysLDIf set to true, the number will always be returned with an area code, even if it is in the country and area specified by CountryCode and AreaCode.
VanityOKIf set to true, vanity numbers will not be converted to numeric format.

There is also an object-oriented interface.
Creates an object that carries default parameters:
$nlz = Number::Phone::Normalize->new( %params );
These functions are equivalent to phone_intl and phone_local but use the %params passed to new as default.
I.e., the following calls:
Number::Phone::Normalize->new( %p1 )->intl( $number, %p2 ) Number::Phone::Normalize->new( %p1 )->local( $number, %p2 )
are equivalent to the follwoing:
phone_intl( $number, %p1, %p2 ); phone_local( $number, %p1, %p2 );

The module does not support more complex dialling plans. It is mostly intended for data input/output to and from databases, not for actually dialling numbers.

Copyright © 2004-2008 Claus Färber <CFAERBER@cpan.org>
It is free software; you can redistribute it and/or modify it under the same terms as perl itself, either version 5.5.0 or, at your option, any later version.