How to make field only take 10 digit mobile number in dynamic CRM using JavaScript

Scenario:  Phone number should be 10-digit number and no alpha value. if phone number more than 10 digit number and include any alpha value so field must be give the warning message.

Screenshot: 




Code : function onchangeofPhone(executionContext) {

        "use strict";

        //This function is used in Location form

        var formContext = executionContext.getFormContext();

        if (formContext.getAttribute("telephone1") != null && formContext.getAttribute("telephone1").getValue() != null) {

            var phone = formContext.getAttribute("telephone1").getValue();

            var match = phone.match(/[0-9]{10}/);

            if (!match || phone.length != 10) {

                setFieldNotification("telephone1", "Please provide 10 digit Phone");

            }

            else {

                clearFieldNotification("telephone1");

            }

        }

function setFieldNotification(controlName, message) {

        "use strict";

        formContext.getControl(controlName).setNotification(message);

    };


function clearFieldNotification(controlName) {

        "use strict";

        formContext.getControl(controlName).clearNotification();

    };

    };


Comments

Popular posts from this blog

latest dynamics 365 interview questions

difference between enable rule vs display rule in ribbon workbench

If i create one record that created record date is older than 3 days, then I want to perform some operation with the help of business rule.