NAME
Number::Phone::Normalize - Normalizes format of Phone Numbers.
SYNOPSIS
use Number::Phone::Normalize;
print phone_intl('+1 (555) 123 4567'); # +1 555 1234567
print phone_local('+49-89-99999999','CountryCode'=>'49'); # 089 99999999
DESCRIPTION
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.
FUNCTIONS
- phone_intl( $number, %params )
-
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.$number
does not contain a country code and%param
does not specify a default), it returnsundef
. - phone_local( $number, %params )
-
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 returnsundef
.
METHODS
There is also an object-oriented interface, which allows you to specify the parameters once, in the constructor.
- new( %params )
-
Creates an object that carries default parameters:
$nlz = Number::Phone::Normalize->new( %params );
- $nlz->intl( $number [, %more_params] )
- $nlz->local( $number [, %more_params] )
-
These functions are equivalent to
phone_intl
andphone_local
but use the%params
passed tonew
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 );
COMMON PARAMETERS
All functions, constructors and methods take the following parameters. Parameters specified in method calls override those given to the constructor.
for input
These parameters specify how the input $number
is interpreted if it is in a non-international format.
CountryCode
-
The local country code. It is added to phone numbers in local format without an country code.
AreaCode
-
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
norLDPrefix
, 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).
for output
These parameters control formatting of the output. Most parameters only affect output in local format.
- CountryCodeOut
-
The local country code. If the number does not have the
CountryCode
specified, it is returned starting with theIntlPrefix
. - AreaCodeOut
-
The local country code. If the number does not have the
CountryCode
specified, it is returned starting with theLDPrefix
. 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
orAlwaysLD
is set to true, it is returned starting withLDPrefixOut
.The default is LDPrefix.
AlwaysLD
-
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
andAreaCode
. VanityOK
-
If set to true, vanity numbers will not be converted to numeric format.
BUGS AND LIMITATIONS
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.
AUTHOR
Claus Färber <CFAERBER@cpan.org>
LICENSE
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.