Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
15

Formatting phone number with possible extension

Community Beginner ,
Mar 13, 2024 Mar 13, 2024

I'm creating a pdf where I collect business phone numbers and extensions (if applicable) in a field "BusinessPhone" and a field "BusinessExt", then later in the document the two may get combined into "BusinessNumber" if there is anything in the BusinessExt field. 

On Blur for Business Phone I have:

this.getField("BusinessNumber").value = event.target.value;

 

On Blur for BusinessExt I have:

if ((event.target.value) !== "") {

     this.getField("BusinessNumber").value = this.getField("BusinessPhone").valueAsString + " ext. " + this.getField("BusinessExt").valueAsString;

} else {

     this.getField("BusinessNumber").value = this.getField("BusinessPhone").valueAsString;

}

 

Those work for me, but I am having issues with the format of BusinessNumber.  If it is just the BusinessPhone value I want it to show as (999) 999-9999 and if it is BusinessPhone + BusinessExt I want it to show as (999) 999-9999 ext. [as many numbers as are filled in for the extension]. 

 

The phone number may be entered with or without () or - so I want to make all phone numbers look uniform.  I use the format Special > Phone Number on all other phone number fields, and would like this one to look the same.  I'm not very strong in javascript, and have been able to google my situation to learn most of what I want to do, but this one keeps putting me into a dead end.  

 

I'm guessing there is something I can put in Custom Formatting but have not yet found anything that works for me.  I appreciate any advice you can give.  Thank you!

TOPICS
JavaScript , PDF , PDF forms
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Mar 13, 2024 Mar 13, 2024

Remove all of your scripts (and field format for "BusinessNumber") then use this script as custom calculation script of "BusinessNumber" field:

var bPhone = this.getField("BusinessPhone").valueAsString;
var bExt = this.getField("BusinessExt").valueAsString;

var bPhoneNum = "";
var bExtNum = "";

if(bPhone !== "")
 bPhoneNum = util.printx("(999) 999-9999",bPhone);
if(bExt !== "" && bPhone !== "")
 bExtNum = "ext."+bExt;
event.value = bPhoneNum+bExtNum;

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 13, 2024 Mar 13, 2024

Remove all of your scripts (and field format for "BusinessNumber") then use this script as custom calculation script of "BusinessNumber" field:

var bPhone = this.getField("BusinessPhone").valueAsString;
var bExt = this.getField("BusinessExt").valueAsString;

var bPhoneNum = "";
var bExtNum = "";

if(bPhone !== "")
 bPhoneNum = util.printx("(999) 999-9999",bPhone);
if(bExt !== "" && bPhone !== "")
 bExtNum = "ext."+bExt;
event.value = bPhoneNum+bExtNum;
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 14, 2024 Mar 14, 2024
LATEST

Thank you so much!  This did exactly what I wanted!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines