Please wait, loading...

 

Validation to accept only Numeric Character in MS CRM

January 7, 2018

Below script is a generic validation which will show for error if field is having anything except numeric value


function ValidateOnlyNumeric(context) {
    var fieldname = context.getEventSource().getName();
    var phone = Xrm.Page.getAttribute(fieldname).getValue();
    if (checkFormat(phone)) {
        Xrm.Page.getControl(fieldname).clearNotification();
    } else {
        Xrm.Page.getControl(fieldname).setNotification(“Please enter only numeric characters”);
    }
}
function checkFormat(phone) {
    var regex = /^d+$/;
    if (regex.test(phone)) {
        return true;
    } else {
        return false;
    }
}

To enable it for any field just register it on change of the required field with function name “ValidateOnlyNumeric” and check “Pass execution context as first parameter ” and save an publish it will start working

Hope it helps

Happy Coding 😊

https://i0.wp.com/microsoftdynamics.in/wp-content/uploads/2020/04/Microsoftdynamics365.png?fit=640%2C651&ssl=1
Microsoft Dynamics Community Profile

Learn more