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
Post a Comment