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.
CountryCode
AreaCode
If phone_intl does not have enough information to build an international number (e.g. $number does not contain a country code and %param does not specify a default), it returns undef.
phone_intl
$number
%param
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. $number does not contain a country code and %param does not specify a default), it returns undef.
phone_local
There is also an object-oriented interface, which allows you to specify the parameters once, in the constructor.
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.
%params
new
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 );
All functions, constructors and methods take the following parameters. Parameters specified in method calls override those given to the constructor.
These parameters specify how the input $number is interpreted if it is in a non-international format.
The local country code. It is added to phone numbers in local format without an country code.
The local area code. It is added to phone numbers in local format without an area code.
IntlPrefix
The 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).
LDPrefix
The 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 control formatting of the output. Most parameters only affect 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.
IntlPrefixOut
The 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.
LDPrefixOut
The 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.
AlwaysLD
The default is LDPrefix.
If 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.
VanityOK
If set to true, vanity numbers will not be converted to numeric format.
The module does not support more complex dialling plans. It is mostly intended for data input and output (especially to and from databases), but not to prepare numbers for dialling.
Claus Färber <CFAERBER@cpan.org>
Copyright 2004-2009 Claus Färber.
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.
To install Number::Phone::Normalize, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Number::Phone::Normalize
CPAN shell
perl -MCPAN -e shell install Number::Phone::Normalize
For more information on module installation, please visit the detailed CPAN module installation guide.