One of my clients requested to validate mobile phone number along with country code.
In India mobile number format should be like +91 1234567890 where +91 is a country code and actual contact number
is of 10 digits.
In general, for other country as well we should have
minimum of 10-digit validations (citation needed)
Here are some testing screen shots for you to understand
and visualize.
Images are self-explanatory.
For formatting a number in US format refer here
JavaScript code to validate for such a
requirement.
updatePhoneNumberFormat:
function (executionContext,
phoneFieldName, phoneLabel)
{
var phoneCleaned;
var phoneNumber = base.attr.getValue(executionContext,
phoneFieldName);
if (phoneNumber != null) {
if (phoneNumber.substr(0, 1) != '+') {
base.attr.getControl(executionContext,
phoneFieldName).clearNotification();
base.attr.getControl(executionContext,
phoneFieldName).setNotification(phoneLabel + '
should be formatted with country code +XX');
return;
}
else {
if (phoneNumber.substr(0, 3) == '+91') {
phoneCleaned = phoneNumber.replace(/[^0-9]/g, "");
if (phoneCleaned.length != 12) {
base.attr.getControl(executionContext,
phoneFieldName).clearNotification();
base.attr.getControl(executionContext,
phoneFieldName).setNotification(phoneLabel + ' for
India country code should be of 10 digit excluding +91');
return;
}
}
else {
phoneCleaned = phoneNumber.replace(/[^0-9]/g, "");
if (phoneCleaned.length < 11) {
base.attr.getControl(executionContext,
phoneFieldName).clearNotification();
base.attr.getControl(executionContext,
phoneFieldName).setNotification(phoneLabel + '
seems to be too short');
return;
}
}
}
base.attr.getControl(executionContext,
phoneFieldName).clearNotification();
}
}
I hope you find this as useful.
You can reach out to me for such validation for your
dynamic CRM Project.
More Reference here
How to format a phone number in Dynamic 365 crm
How to validate mobile with country code in Dynamic CRM
How to validate mobile number in Dynamic CRM
Remove comma from number fields in Dynamic 365 CRM
Thanks.
Vipin
Jaiswal
vipinjaiswal12@gmail.com
No comments:
Post a Comment