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

Popular posts from this blog

Basic Plugin Code in D365 using C#

CURD (Create, Update, Retrieve and Delete) Operation in D365 using Power Shell Script

Meta Data Using WebApiRequest