Formatting phone numbers

General support questions.
Posts: 18
Joined: Sun Dec 12, 2010 11:17 pm
PostPosted: Mon Dec 13, 2010 10:43 pm
Hi all,
I am using the following format for a phone number:
"(" & Left(Filter(Self;"0123456789");3)&")"
& Middle(Filter(Self;"0123456789");4;3)&"-"
& Middle(Filter(Self;"0123456789");7.4;)

What numbers do I change to get the result
(00) 1234-5678 as well as
1234-567-890

Thanks

Milton.
SeedCode Staff
SeedCode Staff
Posts: 2759
Joined: Thu Nov 20, 2003 11:01 am
PostPosted: Wed Dec 15, 2010 7:33 am
Try this one Milton; you may have to fiddle with it a bit. Switch that second line to "str = Self;" (without quotes) to use in your auto-enter calc.

Code: Select all
Let ( [

str = "1234567890x45" ; // the number or field you wish to format or Self

// --- other test cases ----

// str = "Home : 1234567890" ;
// str = "0012345678" ;
// str = "(01) 12345678" ;
// str = "(123) 456-7890" ;

// --- end test cases ---

fstr = Left ( Filter ( str ; "0123456789" ) ; 10 ) ;
exten = Position ( str ; "x" ; 10 ; 1 ) ;
extenstr = If ( exten > 0 ; " x" & Filter ( Middle ( str ; exten ; 99 ) ; "0123456789" ) ) ;
rem = " " & Trim ( Substitute ( Filter ( str ; " abcdefghijklmnopqrstuvwyzABCDEFGHIJKLMNOPQRSTUVWYZ" ) ; [ "etension" ; "" ] ; [ " et" ; "" ] ) )

// by SeedCode for Milton Trickey


] ;

Case (
Left ( fstr; 1 ) = 0 or Middle ( str ; 4; 1 ) = ")" or Middle ( str ; 3; 1 ) = "-" ;

// --- format (##) ####-#### ---

"(" & Left ( fstr ; 2 ) & ") " &
Middle ( fstr ; 3 ; 4 ) & "-" &
Middle ( fstr ; 7 ; 4 )

; // --- format ####-###-### ---

Left ( fstr ; 4 ) & "-" &
Middle ( fstr ; 4 ; 3 ) & "-" &
Middle ( fstr ; 7 ; 3 )

) // End Case

& extenstr & rem

) // End Let
John Sindelar
SeedCode
Posts: 18
Joined: Sun Dec 12, 2010 11:17 pm
PostPosted: Thu Dec 16, 2010 12:16 am
Thanks John,
I shall try that out.
In the mean time I used Left and Right to seperate the phone numbers

Thanks

Milton

Return to General Support

Who is online

Users browsing this forum: Google [Bot] and 2 guests

cron
(855) SEEDCODE
support@seedcode.com
Follow us: