@techabl/core-utils
Version:
A collection of useful utilities.
90 lines (89 loc) • 3.75 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.formHelperValidation = void 0;
var FormHelper = /** @class */ (function () {
function FormHelper() {
}
FormHelper.isUserNameValid = function (userName) {
return this.patterns.userName.test(userName);
};
FormHelper.isEmailValid = function (email) {
return this.patterns.email.test(email);
};
FormHelper.isAddressLengthInvalid = function (value) {
return (value === null || value === void 0 ? void 0 : value.length) < 3 || (value === null || value === void 0 ? void 0 : value.length) > 60;
};
FormHelper.isAddressLength = function (value) {
return (value === null || value === void 0 ? void 0 : value.length) > 2;
};
FormHelper.addressNonEmpty = function (value) {
return this.patterns.nonEmptyString.test(value);
};
FormHelper.isAddressMoreLengthInvalid = function (value) {
return (value === null || value === void 0 ? void 0 : value.length) > 60;
};
FormHelper.isNameLengthInvalid = function (value) {
return (value === null || value === void 0 ? void 0 : value.length) < 3 || (value === null || value === void 0 ? void 0 : value.length) > 30;
};
FormHelper.isPincodeLengthInvalid = function (value) {
return (value === null || value === void 0 ? void 0 : value.length) < 5;
};
FormHelper.isDateValid = function (date, month, year) {
if (!Number(month) || !Number(year)) {
return !!Number(date) && Number(date) <= 31;
}
var daysInMonth = new Date(Number(year), Number(month), 0).getDate();
return Number(date) <= daysInMonth;
};
FormHelper.isMobileNoValid = function (number) {
return this.patterns.mobileNo.test(number);
};
FormHelper.isMonthValid = function (month) {
return !!Number(month) && Number(month) <= 12;
};
FormHelper.isYearValid = function (year) {
return !!Number(year) && year.length === 4;
};
FormHelper.isPasswordValid = function (password) {
return this.patterns.password.test(password);
};
FormHelper.isValidHeight = function (height) {
return !!Number(height) && Number(height) <= 214;
};
FormHelper.isValidWeight = function (weight) {
return !!Number(weight) && Number(weight) <= 150;
};
FormHelper.isNumberAvailable = function (val) {
var matches = val.match(/\d+/g);
if (val) {
if (matches != null)
return true;
else
return false;
}
return true;
};
FormHelper.isValidPAN = function (panNo, partial) {
if (partial === void 0) { partial = true; }
var pattern = partial
? this.patterns.panNumberPartialMatch
: this.patterns.panNumber;
var panNoMatch = "".concat(panNo).trim().match(pattern);
return !!(panNoMatch === null || panNoMatch === void 0 ? void 0 : panNoMatch.length) && panNoMatch[0] === panNo;
};
FormHelper.patterns = {
email: /^\w+([\\.-]?\w+)*@\w+([\\.-]?\w+)*(\.\w{2,3})+$/,
emptySpace: /^\S$|^\S[\s\S]*\S$/,
emptyString: /^\s*$/,
nonEmptyString: /^(?!\s*$).+/,
userName: /^[a-z][a-z0-9_.]+$/,
password: /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,20}$/,
mobileNo: /^\d{0,10}$/,
panNumber: /^[A-Z]{3}P[A-Z]{1}\d{4}[A-Z]{1}$/,
panNumberPartialMatch: /^([A-Z]{3}P[A-Z]{1}\d{4}[A-Z]{1})|([A-Z]{3}P[A-Z]{1}\d{0,4})|([A-Z]{3}P[A-Z]{1})|([A-Z]{3}P)|([A-Z]{0,3})$/,
aadhaarNumber: /^[2-9]{1}\d{3}\d{4}\d{4}$/,
otp: /\b\d{6}\b/,
};
return FormHelper;
}());
exports.formHelperValidation = FormHelper;
;