Expand my Community achievements bar.

SOLVED

Phone Number Format does not transfer to text fields

Avatar

Level 1

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

1 Accepted Solution

Avatar

Correct answer by
Level 8

@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! 

View solution in original post

4 Replies

Avatar

Level 1

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;
}

Avatar

Correct answer by
Level 8

@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! 

Avatar

Level 1
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!