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
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
Glad your problem was solved
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.
Hi Peter,
If you share your code I can comment about.
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
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
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;
}
}
}
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.
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
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.
3.In the Input Mask section click on the pencil of ‘Mask’ property to edit the input.
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.
5.Save and publish.
6.Test:
Regards,
Leah Ju
Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.
André Arnaud de Cal...
292,489
Super User 2025 Season 1
Martin Dráb
231,305
Most Valuable Professional
nmaenpaa
101,156