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 😊