How to set field validation to mobile number using JS in D365
function onLoadEvents()
{
Xrm.Page.getControl('mobilephonenumber').addOnKeyPress(AllowOnlyNumbers);
}
function AllowOnlyNumbers() {
var phoneNo = Xrm.Page.getControl("mobilephonenumber").getValue();
phoneNo = phoneNo.replace(/\D/g, '');
Xrm.Page.getAttribute('mobilephonenumber').setValue(phoneNo);
if (phoneNo.length == 11) {
var formattedPhone = phoneNo.replace(/(\d{3})(\d{3})(\d{4})/, '$1-$2-$3');
Xrm.Page.getAttribute('mobilephonenumber').setValue(formattedPhone);
}
}
Comments
Post a Comment