skelta.maskedinput.js
- Last UpdatedMar 12, 2021
- 1 minute read
(function ()
{
if (skelta.utilities.isUndefined(skelta.forms))
{
// Create the Skelta.Forms namespace
skelta.createNamespace("skelta.forms");
}
skelta.forms.maskedInput = (function ()
{
function maskOperation(elem)
{
var cpf = elem;
//getting key code of pressed key
var key = window.event;
var keycode = (key.which) ? key.which : key.keyCode;
//comparing pressed keycodes
if (keycode > 31 && (keycode < 48 || keycode > 57))
{
//(" You can enter only characters 0 to 9 ");
return false;
}
if ((cpf.value.length == cpf.placeholder.indexOf("-", cpf.value.length)))
{
cpf.value += "-";
return true;
}
if (cpf.value.length == cpf.placeholder.length || cpf.value.length > cpf.placeholder.length)
{
return false;
}
return true;
}
function maskValidation(controlvalue, control, ruleObject)
{
if (!controlvalue) return;
var cpf = control.domElement;
var errMessage = ruleObject.errorMessage;
if (cpf.placeholder.length != controlvalue.length)
{
errorBoolValue = true;
control.validationError(true);
control.validationErrorMessage(errMessage);
control.validationErrorCode(errorConstants.valueValidationRules);
}
}
return {
keyPress: maskOperation,
validation: maskValidation
}
}());
})();