Formatting phone numbers
Posted:
Mon Dec 13, 2010 10:43 pm
by MiltonTrickey
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.
Posted:
Wed Dec 15, 2010 7:33 am
by John Sindelar
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
Posted:
Thu Dec 16, 2010 12:16 am
by MiltonTrickey
Thanks John,
I shall try that out.
In the mean time I used Left and Right to seperate the phone numbers
Thanks
Milton