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 and Methods
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. neither $number
does not contain a country code and %param
does not specify a default), it returns undef.
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. neither $number
does not contain a country code and %param
does not specify a default), it returns undef.
Parameters
Interpreting $number
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
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).
Formatting output
These parameters specify how the output is formatted. Most parameters only have an effect on output in local format.
CountryCodeOut
The local country code. If the number does not have the CountryCode
specified, it is returned starting with the IntlPrefix
.
AreaCodeOut
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
.
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
and AreaCode
.
VanityOK
If set to true, vanity numbers will not be converted to numeric format.
METHODS
There is also an object-oriented interface.
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
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 );
BUGS AND LIMITATIONS
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.
AUTHOR/LICENSE
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.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 386:
Non-ASCII character seen before =encoding in '©'. Assuming UTF-8