Notifications
Announcements
No record found.
I need to put UK mobile number validation on a field. Can someone share a working JavaScript?
*This post is locked for comments
Hi Snitika,
Did you check existing forum posts like below:
social.microsoft.com/.../dynamics-crm-2011-uk-phone-number-javascript-validation
community.dynamics.com/.../119483
These should help you.
Take a look at the following post.
community.dynamics.com/.../formatting-phone-number
Maybe it will help.
Here is my code which keeps giving me Script Error
function formatPhoneNumber()
{
var phoneNumber = Xrm.Page.getAttribute("mobilephone").getValue()
var fixedNumber = string.replace(/[^0-9]/g, '');
var output = "";
switch (fixedNumber.length)
case 7:
output = fixedNumber.substring(0, 3) + "-" + fixedNumber.substring(4, 7);
break;
case 10:
output = "(" + fixedNumber.substring(0, 3) + ") " + fixedNumber.substring(4, 6) + "-" + fixedNumber.substring(7, 10);
case 11:
if (fixedNumber.substring(0, 1) == "1")
output = "(" + fixedNumber.substring(1, 4) + ") " + fixedNumber.substring(5, 7) + " " + fixedNumber.substring(8, 11);
else
output = fixedNumber;
default:
// Error No Output
output = phoneNumber
}
Xrm.Page.getAttribute("mobilephone").setValue(output);
I have corrected your code , please try to run -
function formatPhoneNumber() { var phoneNumber = Xrm.Page.getAttribute("mobilephone").getValue(); var fixedNumber = phoneNumber.replace(/[^0-9]/g, ''); var output = ""; switch (fixedNumber.length) { case 7: output = fixedNumber.substring(0, 3) + "-" + fixedNumber.substring(4, 7); break; case 10: output = "(" + fixedNumber.substring(0, 3) + ") " + fixedNumber.substring(4, 6) + "-" + fixedNumber.substring(7, 10); break; case 11: if (fixedNumber.substring(0, 1) == "1") output = "(" + fixedNumber.substring(1, 4) + ") " + fixedNumber.substring(5, 7) + " " + fixedNumber.substring(8, 11); else output = fixedNumber; break; default: // Error No Output output = phoneNumber break; } Xrm.Page.getAttribute("mobilephone").setValue(output); }
Nothing wrong with the code working fine just change string to phonenumber.
Yes Mahendar you are correct , I did only highlighted one , it was "string" which should be phone number.
Hey Snitika,
For phone number validation or more thing about this number, I use this code below:
var phone = 'Phone number'; var key = 'Your API key'; var default_country = 'Country code'; $.ajax({ url: 'https://api.veriphone.io/v2/verify', method: 'POST', data:{phone: phone, key: key, default_country: default_country}, dataType: 'json', success: function(data) { console.log(data.phone_valid); console.log(data.country); console.log(data.international_number); console.log(data.carrier); } });
And you can get your API key in this link Veriphone
You could also consider using one of the following PCF controls to validate phone number or other fields.
https://pcf.gallery/categories#regex
https://pcf.gallery/check-phone-number-control/
Look at the following post
prudvihub.blogspot.com/.../mobile-number-validation-in-microsoftcrm.html
HI All,
I have requirement to format the phone number based on country for ex : if CA and US +1 and format the phone number and if exceed 10 digit then exclude country code .
Thanks in advance
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
SA-08121319-0 4
Calum MacFarlane 4
Alex Fun Wei Jie 2