There are different methods. I use the following: In the Field (HomePhone) Check the Calculated Value check box and click specify and paste the following script.
[ num = Filter ( HomePhone ;"0123456789" );
num = Case(Left(num;1)= "1"; Middle(num;2;20); num); // remove 'Dial 1' if it's there
len = Length(num) ];
Case( len = 10; TextColor(Left( num; 3) & " " & Middle( num; 4; 3) & "-" & Middle( num ;7;4); RGB(0;0;0)); // with area code
len = 7; TextColor( Left( num; 3) & "-" & Middle( num;4;4); RGB(0;0;0)); // without area code
TextColor(num; RGB(255;0;0) ) ) // wrong length so make text red
And note that you can set this up as an auto-enter calculation that automatically "fixes" the data entered if you also clear the 'do not replace existing value' check box.
And your original calulation field will probably work correctly if you change the calculation field's return type from "number" to "text".
Thanks for the responses Phil. Here is a screen capture that shows the problem. THe calculation results were set to 'text'. I may be better off to use a Trigger Script to open a new window with just the fields 'phone', 'type',and 'mask'. Then just display the calculated result. What do you think? I have found at least three different whay to calculate the formated number and like your the best, except I plan to change it to put parens around the first three numbers.
THe upper phone numbers is the what displays when the record isn't the focus. The lower one (BandG, inc) is the current record.
Seems like your mask field needs an opaque fill color instead of being transparent. Also make sure that access when in Browse mode is not allowed for the upper field.
Oh, I see what's wrong now. Go to Layout setup and clear the "Delineate" check box. That option limits field formats such as fill colors to only the current record. Clear that option to see those settings applied to all records instead of just the current record.