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

Meta Data Using WebApiRequest

Sample CRUD Operations Using C# in MSCRM

Basic Plugin Code in D365 using C#