Standardize The Display Of Phone Numbers

Add this tip to a validation field for a phone number or fax number. It will
standardize the display of the phone number.
@If(Phone="";@Return("");"");
tPhone0 := @ReplaceSubstring (Phone; "("; "");
tPhone2 := @ReplaceSubstring (tPhone0; ")"; "");
tPhone3 := @ReplaceSubstring (tPhone2; "-"; "");
tPhone4 := @ReplaceSubstring (tPhone3; "/"; "");
tPhone5 := @ReplaceSubstring (tPhone4; " "; "");
tPhone6 := @ReplaceSubstring (tPhone5; "_"; "");
tPhone7 := @ReplaceSubstring (tPhone6; "="; "");
tLengthPhone := @Length (tPhone7);
tPhone8:= @If(tLengthPhone > 10 ; @Right (tPhone7; 10); tPhone7);
tNoFrillPhone := @Trim(tPhone8);
REM "Set default area code if none entered to 714";
tArea := @If(tLengthPhone = 7;"714";@Left(tNoFrillPhone;3));
tOther := @If(tLengthPhone = 7;tNoFrillPhone;@Right(tNoFrillPhone; tArea));
tPre := @Left(tOther; 3);
tSuffix := @Right(tOther;4);
tPhoneLen := (tLengthPhone -10);
tDialPre := @If(tLengthPhone > 10; @Left(tPhone7;tPhoneLen); "");
@If(tLengthPhone>10; Phone; tDialPre + "(" + tArea + ") " + tPre + "-" +
tSuffix)

This was first published in November 2000

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.