angular-super-validator
Version:
Angular4 Deep Form Validator
74 lines • 2.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var SuperValidators = /** @class */ (function () {
function SuperValidators() {
}
/**
* Validator that requires controls to have a value greater than a number.
*/
SuperValidators.min = function (min) {
return function (control) {
if (isEmptyInputValue(control.value) || isEmptyInputValue(min)) {
return { 'min': min, 'actualValue': control.value };
}
var value = parseFloat(control.value);
return !isNaN(value) && value < min ? { 'min': min, 'actualValue': control.value } : null;
};
};
/**
* Validator that requires controls to have a value less than a number.
*/
SuperValidators.max = function (max) {
return function (control) {
if (isEmptyInputValue(control.value) || isEmptyInputValue(max)) {
return { 'max': max, 'actualValue': control.value };
}
var value = parseFloat(control.value);
return !isNaN(value) && value > max ? { 'max': max, 'actualValue': control.value } : null;
};
};
SuperValidators.hasNumber = function () {
return function (control) {
var error = { hasNumber: false };
if (!control.value || !/\d/.test(control.value)) {
return error;
}
return null;
};
};
SuperValidators.hasUpper = function () {
return function (control) {
var error = { hasUpper: false };
if (!control.value || control.value.search(/[A-Z]/) < 0) {
return error;
}
return null;
};
};
SuperValidators.hasLower = function () {
return function (control) {
var error = { hasLower: false };
if (!control.value || control.value.search(/[a-z]/) < 0) {
return error;
}
return null;
};
};
SuperValidators.hasSpecial = function () {
return function (control) {
var error = { hasSpecial: false };
var format = /[ !@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/;
if (!control.value || !format.test(control.value)) {
return error;
}
return null;
};
};
return SuperValidators;
}());
exports.SuperValidators = SuperValidators;
function isEmptyInputValue(value) {
// we don't check for string here so it also works with arrays
return value == null || value.length === 0;
}
//# sourceMappingURL=superValidators.js.map