Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

How to add Hyphen on a telephone number field of Contact as 123-345-4567 ?

(0) ShareShare
ReportReport
Posted on by 137

Hi,

The CRM contact form has a business phone number field with the phone number entered like this: 123456789,

Now, I want to add hyphen to it as 123-456-6789,

Can anybody help me how to add it?

Thanks  a lot,

Peter

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to add Hyphen on a telephone number field of Contact as 123-345-4567 ?

    Glad your problem was solved

  • Suggested answer
    Peter Cong Profile Picture
    Peter Cong 137 on at
    RE: How to add Hyphen on a telephone number field of Contact as 123-345-4567 ?

    Thank you so much again, the issue is resolved.

    It was caused by the path of javascript function, basically, in the function field of Handler property window, it should be specifically with project name + form name + function name, for example, crmProject.Contact.formatPhoneNumber; I was just using the function name formatPhoneNumber which caused it can not be found.

  • necsa Profile Picture
    necsa 3,455 on at
    RE: How to add Hyphen on a telephone number field of Contact as 123-345-4567 ?

    Hi Peter,

    If you share your code I can comment about.

  • Peter Cong Profile Picture
    Peter Cong 137 on at
    RE: How to add Hyphen on a telephone number field of Contact as 123-345-4567 ?

    Hi Necdet, thanks for your help,

    I have the similar codes as yours, but my problem is that my javascript function can not be recognized at all.

    I created a simple javascript function to see if it can be called and bound it with OnChange event of telephone1 field, but when I tested it to enter the number on that field, I got error below:

    One of the scripts for this record has caused an error. For more details, download the log file.

    ReferenceError: xxxxx is not defined at eval (eval at RunHandlerInternal

    Please let me know if there is any thing wrong with my case, thanks

  • Peter Cong Profile Picture
    Peter Cong 137 on at
    RE: How to add Hyphen on a telephone number field of Contact as 123-345-4567 ?

    Hi Leah, Thanks a lot for your help again,

    I tried to create a new field called telephone4 and set the Input Mask to it, but unfortunately, it still doesn't work, the new field also lost the hyperlink (the original field telephone1 has a hyperlink after the number is entered).

    I also tried to create user the old way to create a javascript function to be triggered on OnChange event of telephone1 field, but the new javascript function can not be triggered at all, after I entered a telephone number field, I got error of "One of the scripts for this record has caused an error. For more details, download the log file.

    ReferenceError: xxxx is not defined at eval (eval at RunHandlerInternal

  • Suggested answer
    necsa Profile Picture
    necsa 3,455 on at
    RE: How to add Hyphen on a telephone number field of Contact as 123-345-4567 ?

    Hi Peter,

    Here is javascript which one I use for the same request, you just need to modify it for your environment

    function PhoneNumberFormatNoIntlCode(executionContext){
        var formContext=executionContext.getFormContext();

        var number=formContext.getAttribute("telephone1");
        
        var phoneNumber=number.getValue();
        var formatedTelefonNumber="";
        var phoneNumb="";
            if(phoneNumber !=null){
                
                var regExp=/^0[0-9].*$/;

                var cleanedNumber=phoneNumber.replace(/\D/g, "");
                if(regExp.test(cleanedNumber)) {
                    phoneNumb=cleanedNumber.substr(1,cleanedNumber.length);

                }
                else{
                    phoneNumb=cleanedNumber;
                }
                    if(phoneNumb.length > 11){
                    alert("Bitte Telefonnummer nur mit Ort Vorwahlnummer eingeben. Telefonnummer inklusive mit ort Vorwahl must maximum 11 Stellig sein");
                     }
                    switch(phoneNumb.length){
                
                    case 8:
                    formatedTelefonNumber=phoneNumb.substr(0,4) + "-"+ phoneNumb.substr(4,4);
                    number.setValue(formatedTelefonNumber);
                    break;
                    case 9:
                    formatedTelefonNumber=phoneNumb.substr(0,3) + "-"+ phoneNumb.substr(3,3) + "-" + phoneNumb.substr(6,3);
                    number.setValue(formatedTelefonNumber);
                    break;
                    case 10:
                    formatedTelefonNumber=phoneNumb.substr(0,3) + "-"+ phoneNumb.substr(3,3) + "-" + phoneNumb.substr(6,4);
                    number.setValue(formatedTelefonNumber);
                    break;
                    case 11:
                    formatedTelefonNumber=phoneNumb.substr(0,3) + "-"+ phoneNumb.substr(3,4) + "-" + phoneNumb.substr(7,4);
                    number.setValue(formatedTelefonNumber);
                    break;

                
                    }                          
            }
     }

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to add Hyphen on a telephone number field of Contact as 123-345-4567 ?

    Hi Peter,

    You can create another new phone field and enable ‘Input Mask’ control to it, then you can test the new field can work or not?

    And you can clear cache of browser or change another browser or privacy mode to test again.

    Regards,

    Leah Ju

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.

  • Peter Cong Profile Picture
    Peter Cong 137 on at
    RE: How to add Hyphen on a telephone number field of Contact as 123-345-4567 ?

    Hi Leah,

    Thank you so much for your help, I tried your instruction in CRM V8.2, it won't let me choose Web client option.

    Then I tried it in CRM V9.0, it allows me to choose Web client option, but it does not work. After setting the Input Mask as you instructed and Save it and Publish it, then I tested it by creating a new Contact, the phone number didn't format by hyphen.

    I did refresh the web or even relaunch the CRM form, the Business Phone doesn't format at all,

    Do you know anything wrong? thanks 

    pastedimage1615565265533v1.png

    pastedimage1615565663280v2.png

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to add Hyphen on a telephone number field of Contact as 123-345-4567 ?

    Hi Peter,

    ‘Input Mask’ control can help you format phone number field with your needs.

    Please refer following steps.

    1.Go Settings > Customizations > Customize the system > Entities > Contact > Forms.

    Select one form you need and click business phone number field to open ‘Field Properties’ dialog.

    2.click on the Controls tab in the ‘Field Properties’ dialog, then click on Add Control and select “Input Mask” and click on Add again.

    pastedimage1615542377345v1.png

    3.In the Input Mask section click on the pencil of ‘Mask’ property to edit the input.

    pastedimage1615542508570v2.png

    4.The Configure Property “Mask” window comes up, click on the “Bind to a static value” and fill in the format that you want your phone number to appear in.

    pastedimage1615542578905v3.png

    5.Save and publish.

    6.Test:

    pastedimage1615542802442v4.png

    Regards,

    Leah Ju

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,489 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans