Answered in order of easiest answer to most complex:

> Does it start with a 0?
  No.  I've never encountered any US number requiring a prefix of "0" nor a US 
number being
  written that way.


> US numbers are fixed lenght 11 digits?

  The USA is in the North American Numbering Plan (NANP).  This includes USA, 
Canada, much of the
  Caribbean (Cuba, Jamaica, Barbados for example), some US territories in the 
Pacific (Guam,
  American Samoa).  The NANP's "Country Code" is 1.  In the USA and Canada (I 
think the entirety
  of the NANP) this is followed with a 3 digit area code (National Destination 
Number) followed
  by a 7 digit subscriber number.


> What is the usual representation of a 'local' US number?
  There is no consistent answer.  Consider that the oldest phone network is in 
the USA, and the
  unplanned initial growth and many historic regional governing bodies it 
varies massively.  It
  has also changed greatly over time. GENERALLY speaking people will use the 11 
digit number or
  the 10 digit number (without the "1" country code), but there's not a lot of 
rhyme or reason
  as to which is preferred in one case vs another.




-----Original Message-----
From: Benoît Panizzon via sr-users <[email protected]>
Sent: Friday, May 31, 2024 2:52 AM
To: Pavan Kumar via sr-users <[email protected]>
Cc: Pavan Kumar <[email protected]>; Benoît Panizzon 
<[email protected]>
Subject: [SR-Users] Re: Assistance Needed: Converting 11-Digit US Numbers to 
E.164 in Kamailio

CAUTION: This email originated from outside the organization. Do not click 
links or open attachments unless you recognize the sender and know the content 
is safe.


Hi Kumar

> Before writing the code, I want to know if there is already a solution
> to this problem in one of the modules, so that I won't reinvent the
> wheel.

US numbers are fixed lenght 11 digits? What is the usual representation of a 
'local' US number? Does it start with a 0?

I do this (to translate Swiss local numbers to e164):

$var(check_number) = "012 345 67 89" # local number example, use $rU or $fU or 
whatever you want to translate.
route(TRANSLATE_TO_e164);
$rU = $var(result);

route[TRANSLATE_TO_e164]
{
        $var(result) = 'invalid';
        $var(check_number) = $(var(check_number){s.rmws}); # Remove spaces
        if ($var(check_number) =~ "^\+") {
                $var($result) = $var(check_number); # Already e164
        } else if ($var(check_number) =~ "^00") {
                # international number in local notation replace 00 by +
                $var(result) = "+" + $(var(check_number){s.substr,2,0});
        } else if ($var(check_number) =~ "^0") {
                # Swiss number in local notation replace 0 by +41
                $var(result) = "+41" + $(var(check_number){s.substr,1,0});
        }
}

And of course I have a corresponding TRANSLATE_TO_LOCAL to display numbers to 
the customer in a format they are used to in Switzerland.

--
Mit freundlichen Grüssen

-Benoît Panizzon- @ HomeOffice und normal erreichbar
--
I m p r o W a r e   A G    -    Leiter Commerce Kunden
______________________________________________________

Zurlindenstrasse 29             Tel  +41 61 826 93 00
CH-4133 Pratteln                Fax  +41 61 826 93 01
Schweiz                         Web  http://www.imp.ch/
______________________________________________________
__________________________________________________________
Kamailio - Users Mailing List - Non Commercial Discussions To unsubscribe send 
an email to [email protected]
Important: keep the mailing list in the recipients, do not reply only to the 
sender!
Edit mailing list options or unsubscribe:
__________________________________________________________
Kamailio - Users Mailing List - Non Commercial Discussions
To unsubscribe send an email to [email protected]
Important: keep the mailing list in the recipients, do not reply only to the 
sender!
Edit mailing list options or unsubscribe:

Reply via email to