Phone Number Format does not transfer to text fields | Community
Skip to main content
February 4, 2021
Solved

Phone Number Format does not transfer to text fields

  • February 4, 2021
  • 3 replies
  • 1463 views

I am working on a form where the user enters their information in fields to generate a report. How can I  keep the formatting for the phone numbers entered into the field to transfer to the text field. when the report is generated? I need (123) 456-7890 but end up with 1234567890

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Manjunath_K

@duquette,

Have you tried adding custom logic in javascript to format this phone number? if not please try adding below logic to format phone number with 10 digits.

 

var phoneNumber = '1234567890';

if(phoneNumber.length == 10){
phoneNumber = '('+phoneNumber.substr(0,3)+') '+phoneNumber.substr(3,3)+'-'+phoneNumber.substr(6); //returns formatted phone number (123) 456-7890
}

 

Hope this helps! 

3 replies

Level 8
February 4, 2021

How are you generating the pdf?

DuquetteAuthor
February 4, 2021

I am assigning the value to a variable then recalling it in the report..

 

// Primary Contact Information;

if (pcn.value === ""){
event.value = "Primary Contact:\n\n\nNo Primary Contact on File";
}
else{

event.value = "Primary Contact:\n\n"+pcn.value+"\nWork: "+pcp.value+"\nCell: "+pcpc.value+"\nEmail: "+pce.value;
}

Manjunath_K
Manjunath_KAccepted solution
Level 7
February 4, 2021

@duquette,

Have you tried adding custom logic in javascript to format this phone number? if not please try adding below logic to format phone number with 10 digits.

 

var phoneNumber = '1234567890';

if(phoneNumber.length == 10){
phoneNumber = '('+phoneNumber.substr(0,3)+') '+phoneNumber.substr(3,3)+'-'+phoneNumber.substr(6); //returns formatted phone number (123) 456-7890
}

 

Hope this helps! 

DuquetteAuthor
February 5, 2021
Manjunath, Thank you for your help - I had tried several variations to format the phone number - the solution was a combination of your help and declaring the variable as a string. Again - Thank You!