Here' a basic script that formats U.S. phone numbers to appear in the
consistent formats 1-408-555-0000, (408) 555-0000, or 555-0000. If you try
to format something that doesn't look like a phone number, the script will
leave the value as you entered it. To use the script, attach it to any
field that contains a telephone number. The number will be reformatted
whenever you make a new entry or change text in that field. This script is
an example. Modify it to create your own customized version or to format
numbers for your area.
on closeField
ð Assuming first line contains phone number.
put line 1 of me into PhoneNum
ðð Remove non-dial characters.
repeat with CurChar = length of PhoneNum down to 1
if char CurChar of PhoneNum is in ")(-" & space & tab
then delete char CurChar of PhoneNum
end repeat
ðð Format a phone number.
if length of word 1 of PhoneNum is 11 ð
and char 1 of PhoneNum is "" then
put "-" after char 7 of PhoneNum
put "-" after char 4 of PhoneNum
put "-" after char 1 of PhoneNum
else if length of word 1 of PhoneNum is 10 then
put "-" after char 6 of PhoneNum
put ")" after char 3 of PhoneNum
put "(" before PhoneNum
put PhoneNum into line 1 of me
else if length of word 1 of PhoneNum is 7 then
put "-" after char 3 of PhoneNum
put PhoneNum into line 1 of me
ðð end if
If the number does not match, then do nothing.
pass closeField
end closeField
This article is adapted from the Claris Tech Info database.