quantique-field-validator 1.0.9 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +176 -0
- package/dist/messages/defaultErrorMessages.d.ts +8 -0
- package/dist/messages/defaultErrorMessages.d.ts.map +1 -0
- package/dist/messages/defaultErrorMessages.js +38 -0
- package/dist/types/index.d.ts +97 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/utils/safeRegex.d.ts +22 -0
- package/dist/utils/safeRegex.d.ts.map +1 -0
- package/dist/utils/safeRegex.js +32 -0
- package/dist/validators/validateAadhaar.d.ts +8 -0
- package/dist/validators/validateAadhaar.d.ts.map +1 -0
- package/dist/validators/validateAadhaar.js +20 -0
- package/dist/validators/validateAddress.d.ts +8 -0
- package/dist/validators/validateAddress.d.ts.map +1 -0
- package/dist/validators/validateAddress.js +38 -0
- package/dist/validators/validateAlphanumeric.d.ts +8 -0
- package/dist/validators/validateAlphanumeric.d.ts.map +1 -0
- package/dist/validators/validateAlphanumeric.js +38 -0
- package/dist/validators/validateBankIFSC.d.ts +9 -0
- package/dist/validators/validateBankIFSC.d.ts.map +1 -0
- package/dist/validators/validateBankIFSC.js +33 -0
- package/dist/validators/validateChassisNumber.d.ts +9 -0
- package/dist/validators/validateChassisNumber.d.ts.map +1 -0
- package/dist/validators/validateChassisNumber.js +33 -0
- package/dist/validators/validateCustom.d.ts +9 -0
- package/dist/validators/validateCustom.d.ts.map +1 -0
- package/dist/validators/validateCustom.js +26 -0
- package/dist/validators/validateDate.d.ts +11 -0
- package/dist/validators/validateDate.d.ts.map +1 -0
- package/dist/validators/validateDate.js +119 -0
- package/dist/validators/validateEmail.d.ts +9 -0
- package/dist/validators/validateEmail.d.ts.map +1 -0
- package/dist/validators/validateEmail.js +33 -0
- package/dist/validators/validateEngineNumber.d.ts +8 -0
- package/dist/validators/validateEngineNumber.d.ts.map +1 -0
- package/dist/validators/validateEngineNumber.js +32 -0
- package/dist/validators/validateFirstMiddleLastName.d.ts +9 -0
- package/dist/validators/validateFirstMiddleLastName.d.ts.map +1 -0
- package/dist/validators/validateFirstMiddleLastName.js +33 -0
- package/dist/validators/validateFloatNumber.d.ts +13 -0
- package/dist/validators/validateFloatNumber.d.ts.map +1 -0
- package/dist/validators/validateFloatNumber.js +75 -0
- package/dist/validators/validateGST.d.ts +9 -0
- package/dist/validators/validateGST.d.ts.map +1 -0
- package/dist/validators/validateGST.js +21 -0
- package/dist/validators/validateIPAddress.d.ts +8 -0
- package/dist/validators/validateIPAddress.d.ts.map +1 -0
- package/dist/validators/validateIPAddress.js +51 -0
- package/dist/validators/validateMobile.d.ts +9 -0
- package/dist/validators/validateMobile.d.ts.map +1 -0
- package/dist/validators/validateMobile.js +21 -0
- package/dist/validators/validateName.d.ts +11 -0
- package/dist/validators/validateName.d.ts.map +1 -0
- package/dist/validators/validateName.js +53 -0
- package/dist/validators/validateNumber.d.ts +8 -0
- package/dist/validators/validateNumber.d.ts.map +1 -0
- package/dist/validators/validateNumber.js +51 -0
- package/dist/validators/validatePanCard.d.ts +8 -0
- package/dist/validators/validatePanCard.d.ts.map +1 -0
- package/dist/validators/validatePanCard.js +20 -0
- package/dist/validators/validatePassword.d.ts +4 -0
- package/dist/validators/validatePassword.d.ts.map +1 -0
- package/dist/validators/validatePassword.js +47 -0
- package/dist/validators/validatePincode.d.ts +8 -0
- package/dist/validators/validatePincode.d.ts.map +1 -0
- package/dist/validators/validatePincode.js +20 -0
- package/dist/validators/validateRTO.d.ts +12 -0
- package/dist/validators/validateRTO.d.ts.map +1 -0
- package/dist/validators/validateRTO.js +45 -0
- package/dist/validators/validateString.d.ts +8 -0
- package/dist/validators/validateString.d.ts.map +1 -0
- package/dist/validators/validateString.js +39 -0
- package/dist/validators/validateURL.d.ts +9 -0
- package/dist/validators/validateURL.d.ts.map +1 -0
- package/dist/validators/validateURL.js +51 -0
- package/package.json +50 -9
- package/.github/workflows/publish.yml +0 -31
- package/Messages/defaultErrorMessages.js +0 -27
- package/Validators/ValidateChassisNumber.js +0 -37
- package/Validators/validateAadhaar.js +0 -18
- package/Validators/validateAddress.js +0 -38
- package/Validators/validateAlphanumeric.js +0 -47
- package/Validators/validateBankIFSC.js +0 -41
- package/Validators/validateCustom.js +0 -18
- package/Validators/validateDate.js +0 -166
- package/Validators/validateEmail.js +0 -39
- package/Validators/validateEngineNumber.js +0 -37
- package/Validators/validateFirstMiddleLastName.js +0 -36
- package/Validators/validateFloatNumber.js +0 -108
- package/Validators/validateGST.js +0 -19
- package/Validators/validateIPAddress.js +0 -41
- package/Validators/validateMobile.js +0 -116
- package/Validators/validateName.js +0 -67
- package/Validators/validateNumber.js +0 -75
- package/Validators/validatePanCard.js +0 -23
- package/Validators/validatePassword.js +0 -38
- package/Validators/validateRTO.js +0 -41
- package/Validators/validateString.js +0 -41
- package/index.js +0 -194
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
// Address validation
|
|
2
|
-
const validateAddress = (value, rules, defaultErrorMessages, type) => {
|
|
3
|
-
// Check length constraints
|
|
4
|
-
if (rules?.minLength && value.length < rules?.minLength) {
|
|
5
|
-
return {
|
|
6
|
-
isValid: false,
|
|
7
|
-
error:
|
|
8
|
-
rules?.errorMessages?.minLength ||
|
|
9
|
-
defaultErrorMessages(rules, type).minLength,
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
if (rules?.maxLength && value.length > rules?.maxLength) {
|
|
14
|
-
return {
|
|
15
|
-
isValid: false,
|
|
16
|
-
error:
|
|
17
|
-
rules?.errorMessages?.maxLength ||
|
|
18
|
-
defaultErrorMessages(rules, type).maxLength,
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// Check against custom regex if provided
|
|
23
|
-
const defaultRegex = /^[a-zA-Z0-9\s,./\-#&:]+$/;
|
|
24
|
-
const regexToUse = rules?.regex ? new RegExp(rules.regex) : defaultRegex;
|
|
25
|
-
|
|
26
|
-
if (!regexToUse.test(value)) {
|
|
27
|
-
return {
|
|
28
|
-
isValid: false,
|
|
29
|
-
error:
|
|
30
|
-
rules?.errorMessages?.invalid ||
|
|
31
|
-
defaultErrorMessages(rules, type).invalid,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return { isValid: true, error: "" };
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
module.exports = validateAddress;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
// Alphanumeric validation
|
|
2
|
-
const validateAlphanumeric = (value, rules, defaultErrorMessages, type) => {
|
|
3
|
-
// Check length constraints if value is a string
|
|
4
|
-
if (typeof value !== "string") {
|
|
5
|
-
return {
|
|
6
|
-
isValid: false,
|
|
7
|
-
error:
|
|
8
|
-
rules?.errorMessages?.invalid ||
|
|
9
|
-
defaultErrorMessages(rules, type).Alphanumeric,
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
if (rules?.minLength && value.length < rules?.minLength) {
|
|
13
|
-
return {
|
|
14
|
-
isValid: false,
|
|
15
|
-
error:
|
|
16
|
-
rules?.errorMessages?.minLength ||
|
|
17
|
-
defaultErrorMessages(rules, type).minLength,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (rules?.maxLength && value.length > rules?.maxLength) {
|
|
22
|
-
return {
|
|
23
|
-
isValid: false,
|
|
24
|
-
error:
|
|
25
|
-
rules?.errorMessages?.maxLength ||
|
|
26
|
-
defaultErrorMessages(rules, type).maxLength,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Check against custom regex if provided
|
|
31
|
-
const defaultRegex = /^[a-z0-9]+$/;
|
|
32
|
-
const regexToUse = rules?.regex ? new RegExp(rules.regex) : defaultRegex;
|
|
33
|
-
|
|
34
|
-
if (!regexToUse.test(value)) {
|
|
35
|
-
return {
|
|
36
|
-
isValid: false,
|
|
37
|
-
error:
|
|
38
|
-
rules?.errorMessages?.invalid ||
|
|
39
|
-
defaultErrorMessages(rules, type).Alphanumeric ||
|
|
40
|
-
defaultErrorMessages(rules, type).invalid,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return { isValid: true, error: "" };
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
module.exports = validateAlphanumeric;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
//Bank IFSC validation
|
|
2
|
-
const validateBankIFSC = (
|
|
3
|
-
value,
|
|
4
|
-
rules = { minLength: 11, maxLength: 11 },
|
|
5
|
-
defaultErrorMessages,
|
|
6
|
-
type
|
|
7
|
-
) => {
|
|
8
|
-
if (rules?.minLength && value?.length < rules?.minLength) {
|
|
9
|
-
return {
|
|
10
|
-
isValid: false,
|
|
11
|
-
error:
|
|
12
|
-
rules?.errorMessages?.minLength ||
|
|
13
|
-
defaultErrorMessages(rules, type).minLength,
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if (rules?.maxLength && value?.length > rules?.maxLength) {
|
|
18
|
-
return {
|
|
19
|
-
isValid: false,
|
|
20
|
-
error:
|
|
21
|
-
rules?.errorMessages?.maxLength ||
|
|
22
|
-
defaultErrorMessages(rules, type).maxLength,
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const defaultRegex = /^[A-Z]{4}0[A-Z0-9]{6}$/;
|
|
27
|
-
const regexToUse = rules?.regex ? new RegExp(rules.regex) : defaultRegex;
|
|
28
|
-
if (!regexToUse.test(value)) {
|
|
29
|
-
return {
|
|
30
|
-
isValid: false,
|
|
31
|
-
error: rules?.errorMessages?.invalid
|
|
32
|
-
? rules?.errorMessages?.invalid
|
|
33
|
-
: defaultErrorMessages(rules, type).ifsc ||
|
|
34
|
-
defaultErrorMessages(rules, type).invalid,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return { isValid: true, error: '' };
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
module.exports = validateBankIFSC;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// Custom validation
|
|
2
|
-
const validateCustom = (value, rules, defaultErrorMessages, type) => {
|
|
3
|
-
// Check against custom regex if provided
|
|
4
|
-
const regexToUse = new RegExp(rules.regex);
|
|
5
|
-
|
|
6
|
-
if (!regexToUse.test(value)) {
|
|
7
|
-
return {
|
|
8
|
-
isValid: false,
|
|
9
|
-
error:
|
|
10
|
-
rules?.errorMessages?.invalid ||
|
|
11
|
-
defaultErrorMessages(rules, type).invalid,
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return { isValid: true, error: "" };
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
module.exports = validateCustom;
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
// Date validation
|
|
2
|
-
|
|
3
|
-
// {
|
|
4
|
-
// minAge: 18,
|
|
5
|
-
// maxAge: 65,
|
|
6
|
-
// minPlus: 2,
|
|
7
|
-
// maxPlus: 30,
|
|
8
|
-
// minMinus: 5,
|
|
9
|
-
// maxMinus: 365,
|
|
10
|
-
// unit: "month", // or "day" or "year"
|
|
11
|
-
// errorMessages: {
|
|
12
|
-
// minPlus: "Date must be at least 2 months ahead!",
|
|
13
|
-
// }
|
|
14
|
-
// }
|
|
15
|
-
|
|
16
|
-
const validateDate = (
|
|
17
|
-
value,
|
|
18
|
-
rules = { format: "DD/MM/YYYY" },
|
|
19
|
-
defaultErrorMessages,
|
|
20
|
-
type
|
|
21
|
-
) => {
|
|
22
|
-
const parseDateByFormat = (value, format) => {
|
|
23
|
-
if (!format) return new Date(value); // fallback to default
|
|
24
|
-
|
|
25
|
-
const separator = format.includes("/") ? "/" : "-";
|
|
26
|
-
const parts = value.split(separator);
|
|
27
|
-
const formatParts = format.split(separator);
|
|
28
|
-
|
|
29
|
-
if (parts.length !== 3 || formatParts.length !== 3) return new Date(NaN);
|
|
30
|
-
|
|
31
|
-
const dateParts = {};
|
|
32
|
-
formatParts.forEach((part, index) => {
|
|
33
|
-
dateParts[part] = parseInt(parts[index], 10);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
const day = dateParts["DD"];
|
|
37
|
-
const month = (dateParts["MM"] || 1) - 1; // Month is 0-indexed
|
|
38
|
-
const year = dateParts["YYYY"];
|
|
39
|
-
|
|
40
|
-
return new Date(year, month, day);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const applyOffset = (baseDate, value, unit, operation = "add") => {
|
|
44
|
-
const date = new Date(baseDate);
|
|
45
|
-
const multiplier = operation === "subtract" ? -1 : 1;
|
|
46
|
-
|
|
47
|
-
switch (unit) {
|
|
48
|
-
case "month":
|
|
49
|
-
case "months":
|
|
50
|
-
date.setMonth(date.getMonth() + value * multiplier);
|
|
51
|
-
break;
|
|
52
|
-
case "year":
|
|
53
|
-
case "years":
|
|
54
|
-
date.setFullYear(date.getFullYear() + value * multiplier);
|
|
55
|
-
break;
|
|
56
|
-
default:
|
|
57
|
-
date.setDate(date.getDate() + value * multiplier);
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return date;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const parsedDate = parseDateByFormat(value, rules?.format);
|
|
65
|
-
const today = new Date();
|
|
66
|
-
today.setHours(0, 0, 0, 0); // Normalize for accurate comparisons
|
|
67
|
-
|
|
68
|
-
if (isNaN(parsedDate.getTime())) {
|
|
69
|
-
return {
|
|
70
|
-
isValid: false,
|
|
71
|
-
error:
|
|
72
|
-
rules?.errorMessages?.invalid ||
|
|
73
|
-
defaultErrorMessages(rules, type)?.invalid ||
|
|
74
|
-
"Invalid date format",
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Age check (minAge)
|
|
79
|
-
if (rules?.minAge) {
|
|
80
|
-
const minAgeDate = new Date();
|
|
81
|
-
minAgeDate.setFullYear(minAgeDate.getFullYear() - rules.minAge);
|
|
82
|
-
if (parsedDate > minAgeDate) {
|
|
83
|
-
return {
|
|
84
|
-
isValid: false,
|
|
85
|
-
error:
|
|
86
|
-
rules?.errorMessages?.minAge ||
|
|
87
|
-
defaultErrorMessages(rules, type)?.minAge ||
|
|
88
|
-
`You must be at least ${rules.minAge} years old`,
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// Age check (maxAge)
|
|
94
|
-
if (rules?.maxAge) {
|
|
95
|
-
const maxAgeDate = new Date();
|
|
96
|
-
maxAgeDate.setFullYear(maxAgeDate.getFullYear() - rules.maxAge);
|
|
97
|
-
if (parsedDate < maxAgeDate) {
|
|
98
|
-
return {
|
|
99
|
-
isValid: false,
|
|
100
|
-
error:
|
|
101
|
-
rules?.errorMessages?.maxAge ||
|
|
102
|
-
defaultErrorMessages(rules, type)?.maxAge ||
|
|
103
|
-
`You must be at most ${rules.maxAge} years old`,
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Handle relative rules with units (default to "day")
|
|
109
|
-
const unit = rules?.unit || "day";
|
|
110
|
-
|
|
111
|
-
if (rules?.minMinus) {
|
|
112
|
-
const minPast = applyOffset(today, rules.minMinus, unit, "subtract");
|
|
113
|
-
if (parsedDate < minPast) {
|
|
114
|
-
return {
|
|
115
|
-
isValid: false,
|
|
116
|
-
error:
|
|
117
|
-
rules?.errorMessages?.minMinus ||
|
|
118
|
-
defaultErrorMessages(rules, type)?.minMinus ||
|
|
119
|
-
`Date should not be earlier than ${rules.minMinus} ${unit}(s) ago`,
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (rules?.maxPlus) {
|
|
125
|
-
const maxFuture = applyOffset(today, rules.maxPlus, unit, "add");
|
|
126
|
-
if (parsedDate > maxFuture) {
|
|
127
|
-
return {
|
|
128
|
-
isValid: false,
|
|
129
|
-
error:
|
|
130
|
-
rules?.errorMessages?.maxPlus ||
|
|
131
|
-
defaultErrorMessages(rules, type)?.maxPlus ||
|
|
132
|
-
`Date should not be more than ${rules.maxPlus} ${unit}(s) in the future`,
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (rules?.minPlus) {
|
|
138
|
-
const minFuture = applyOffset(today, rules.minPlus, unit, "add");
|
|
139
|
-
if (parsedDate < minFuture) {
|
|
140
|
-
return {
|
|
141
|
-
isValid: false,
|
|
142
|
-
error:
|
|
143
|
-
rules?.errorMessages?.minPlus ||
|
|
144
|
-
defaultErrorMessages(rules, type)?.minPlus ||
|
|
145
|
-
`Date should be at least ${rules.minPlus} ${unit}(s) in the future`,
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (rules?.maxMinus) {
|
|
151
|
-
const maxPast = applyOffset(today, rules.maxMinus, unit, "subtract");
|
|
152
|
-
if (parsedDate > maxPast) {
|
|
153
|
-
return {
|
|
154
|
-
isValid: false,
|
|
155
|
-
error:
|
|
156
|
-
rules?.errorMessages?.maxMinus ||
|
|
157
|
-
defaultErrorMessages(rules, type)?.maxMinus ||
|
|
158
|
-
`Date should not be later than ${rules.maxMinus} ${unit}(s) ago`,
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return { isValid: true, error: "" };
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
module.exports = validateDate;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
// Email validation
|
|
2
|
-
const validateEmail = (value, rules, defaultErrorMessages, type) => {
|
|
3
|
-
// Check length constraints
|
|
4
|
-
if (rules?.minLength && value.length < rules?.minLength) {
|
|
5
|
-
return {
|
|
6
|
-
isValid: false,
|
|
7
|
-
error:
|
|
8
|
-
rules?.errorMessages?.minLength ||
|
|
9
|
-
defaultErrorMessages(rules, type).minLength,
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
if (rules?.maxLength && value.length > rules?.maxLength) {
|
|
14
|
-
return {
|
|
15
|
-
isValid: false,
|
|
16
|
-
error:
|
|
17
|
-
rules?.errorMessages?.maxLength ||
|
|
18
|
-
defaultErrorMessages(rules, type).maxLength,
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// Check against custom regex if provided
|
|
23
|
-
const defaultRegex =
|
|
24
|
-
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}))$/;
|
|
25
|
-
const regexToUse = rules?.regex ? new RegExp(rules.regex) : defaultRegex;
|
|
26
|
-
|
|
27
|
-
if (!regexToUse.test(value)) {
|
|
28
|
-
return {
|
|
29
|
-
isValid: false,
|
|
30
|
-
error:
|
|
31
|
-
rules?.errorMessages?.invalid ||
|
|
32
|
-
defaultErrorMessages(rules, type).invalid,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return { isValid: true, error: "" };
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
module.exports = validateEmail;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
// ChassisNumber validation
|
|
2
|
-
const validateEngineNumber = (value, rules, defaultErrorMessages, type) => {
|
|
3
|
-
if (rules?.minLength && value?.length < rules?.minLength) {
|
|
4
|
-
return {
|
|
5
|
-
isValid: false,
|
|
6
|
-
error:
|
|
7
|
-
rules?.errorMessages?.minLength ||
|
|
8
|
-
defaultErrorMessages(rules, type).minLength,
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if (rules?.maxLength && value?.length > rules?.maxLength) {
|
|
13
|
-
return {
|
|
14
|
-
isValid: false,
|
|
15
|
-
error:
|
|
16
|
-
rules?.errorMessages?.maxLength ||
|
|
17
|
-
defaultErrorMessages(rules, type).maxLength,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const defaultRegex = /^[A-Za-z0-9.]{5,25}$/;
|
|
22
|
-
const regexToUse = rules?.regex ? new RegExp(rules.regex) : defaultRegex;
|
|
23
|
-
|
|
24
|
-
if (!regexToUse.test(value)) {
|
|
25
|
-
return {
|
|
26
|
-
isValid: false,
|
|
27
|
-
error: rules?.errorMessages?.invalid
|
|
28
|
-
? rules?.errorMessages?.invalid
|
|
29
|
-
: defaultErrorMessages(rules, type).engineNumber ||
|
|
30
|
-
defaultErrorMessages(rules, type).invalid,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return { isValid: true, error: "" };
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
module.exports = validateEngineNumber;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
// First/Middle/Last Name validation
|
|
2
|
-
const validateFirstMiddleLastName = (value, rules, defaultErrorMessages, type) => {
|
|
3
|
-
if (rules?.minLength && value?.length < rules?.minLength) {
|
|
4
|
-
return {
|
|
5
|
-
isValid: false,
|
|
6
|
-
error:
|
|
7
|
-
rules?.errorMessages?.minLength ||
|
|
8
|
-
defaultErrorMessages(rules, type).minLength,
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if (rules?.maxLength && value?.length > rules?.maxLength) {
|
|
13
|
-
return {
|
|
14
|
-
isValid: false,
|
|
15
|
-
error:
|
|
16
|
-
rules?.errorMessages?.maxLength ||
|
|
17
|
-
defaultErrorMessages(rules, type).maxLength,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const defaultRegex = /^[a-zA-ZàáâäãåąčćęèéêëėįìíîïłńòóôöõøùúûüųūÿýżźñçčšžÀÁÂÄÃÅĄĆČĖĘÈÉÊËÌÍÎÏĮŁŃÒÓÔÖÕØÙÚÛÜŲŪŸÝŻŹÑßÇŒÆČŠŽ∂ð]+$/u;
|
|
22
|
-
const regexToUse = rules?.regex ? new RegExp(rules.regex) : defaultRegex;
|
|
23
|
-
if (!regexToUse.test(value)) {
|
|
24
|
-
return {
|
|
25
|
-
isValid: false,
|
|
26
|
-
error: rules?.errorMessages?.invalid
|
|
27
|
-
? rules?.errorMessages?.invalid
|
|
28
|
-
: defaultErrorMessages(rules, type).name ||
|
|
29
|
-
defaultErrorMessages(rules, type).invalid,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return { isValid: true, error: '' };
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
module.exports = validateFirstMiddleLastName;
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
// Float Number Validation with Precision Check
|
|
2
|
-
|
|
3
|
-
// const rules = {
|
|
4
|
-
// decimalPrecision: 2, // allow only 2 digits after decimal
|
|
5
|
-
// maxWholeDigits: 6, // allow up to 6 digits before decimal
|
|
6
|
-
// minValue: 0.01,
|
|
7
|
-
// maxValue: 999999.99,
|
|
8
|
-
// };
|
|
9
|
-
|
|
10
|
-
const validateFloatNumber = (value, rules, defaultErrorMessages, type) => {
|
|
11
|
-
// Reject if value contains spaces
|
|
12
|
-
if (/\s/.test(value)) {
|
|
13
|
-
return {
|
|
14
|
-
isValid: false,
|
|
15
|
-
error:
|
|
16
|
-
rules?.errorMessages?.invalid ||
|
|
17
|
-
defaultErrorMessages(rules, type).noSpace ||
|
|
18
|
-
defaultErrorMessages(rules, type).invalid,
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// Default float regex (supports optional decimal)
|
|
23
|
-
const defaultFloatRegex = /^\d+(\.\d+)?$/;
|
|
24
|
-
const regexToUse = rules?.regex ? new RegExp(rules.regex) : defaultFloatRegex;
|
|
25
|
-
|
|
26
|
-
if (!regexToUse.test(value)) {
|
|
27
|
-
return {
|
|
28
|
-
isValid: false,
|
|
29
|
-
error:
|
|
30
|
-
rules?.errorMessages?.invalid ||
|
|
31
|
-
defaultErrorMessages(rules, type).invalid ||
|
|
32
|
-
"Please enter a valid amount (e.g., 123.45)",
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const numberValue = Number(value);
|
|
37
|
-
|
|
38
|
-
// Decimal precision validation
|
|
39
|
-
if (rules?.decimalPrecision !== undefined) {
|
|
40
|
-
const decimalPart = value.split(".")[1];
|
|
41
|
-
const actualPrecision = decimalPart ? decimalPart.length : 0;
|
|
42
|
-
if (actualPrecision > rules.decimalPrecision) {
|
|
43
|
-
return {
|
|
44
|
-
isValid: false,
|
|
45
|
-
error:
|
|
46
|
-
rules?.errorMessages?.decimalPrecision ||
|
|
47
|
-
`Only up to ${rules.decimalPrecision} digits allowed after decimal.`,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Whole number digit validation
|
|
53
|
-
if (rules?.maxWholeDigits !== undefined) {
|
|
54
|
-
const wholePart = value.split(".")[0];
|
|
55
|
-
if (wholePart.length > rules.maxWholeDigits) {
|
|
56
|
-
return {
|
|
57
|
-
isValid: false,
|
|
58
|
-
error:
|
|
59
|
-
rules?.errorMessages?.maxWholeDigits ||
|
|
60
|
-
`Only up to ${rules.maxWholeDigits} digits allowed before decimal.`,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Length checks (on the full string)
|
|
66
|
-
if (rules?.minLength && value.length < rules.minLength) {
|
|
67
|
-
return {
|
|
68
|
-
isValid: false,
|
|
69
|
-
error:
|
|
70
|
-
rules?.errorMessages?.minLength ||
|
|
71
|
-
defaultErrorMessages(rules, type).minLength,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (rules?.maxLength && value.length > rules.maxLength) {
|
|
76
|
-
return {
|
|
77
|
-
isValid: false,
|
|
78
|
-
error:
|
|
79
|
-
rules?.errorMessages?.maxLength ||
|
|
80
|
-
defaultErrorMessages(rules, type).maxLength,
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Value range checks
|
|
85
|
-
if (rules?.minValue !== undefined && numberValue < rules.minValue) {
|
|
86
|
-
return {
|
|
87
|
-
isValid: false,
|
|
88
|
-
error:
|
|
89
|
-
rules?.errorMessages?.minValue ||
|
|
90
|
-
defaultErrorMessages(rules, type).minValue ||
|
|
91
|
-
`Amount must be at least ${rules.minValue}`,
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (rules?.maxValue !== undefined && numberValue > rules.maxValue) {
|
|
96
|
-
return {
|
|
97
|
-
isValid: false,
|
|
98
|
-
error:
|
|
99
|
-
rules?.errorMessages?.maxValue ||
|
|
100
|
-
defaultErrorMessages(rules, type).maxValue ||
|
|
101
|
-
`Amount must not exceed ${rules.maxValue}`,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return { isValid: true, error: "" };
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
module.exports = validateFloatNumber;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// GSTIN validation
|
|
2
|
-
const validateGST = (value, rules, defaultErrorMessages, type) => {
|
|
3
|
-
const defaultRegex = /^\d{2}[A-Z]{5}\d{4}[A-Z]{1}[A-Z\d]{1}Z{1}[A-Z\d]{1}$/;
|
|
4
|
-
const regexToUse = rules?.regex ? new RegExp(rules.regex) : defaultRegex;
|
|
5
|
-
|
|
6
|
-
if (!regexToUse.test(value)) {
|
|
7
|
-
return {
|
|
8
|
-
isValid: false,
|
|
9
|
-
error:
|
|
10
|
-
rules?.errorMessages?.regex ||
|
|
11
|
-
rules?.errorMessages?.invalid ||
|
|
12
|
-
defaultErrorMessages(rules, type).invalid,
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return { isValid: true, error: '' };
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
module.exports = validateGST;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
// IP Address validation
|
|
2
|
-
const validateIPAddress = (value, rules, defaultErrorMessages, type) => {
|
|
3
|
-
if (rules?.minLength && value?.length < rules?.minLength) {
|
|
4
|
-
return {
|
|
5
|
-
isValid: false,
|
|
6
|
-
error:
|
|
7
|
-
rules?.errorMessages?.minLength ||
|
|
8
|
-
defaultErrorMessages(rules, type).minLength,
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if (rules?.maxLength && value?.length > rules?.maxLength) {
|
|
13
|
-
return {
|
|
14
|
-
isValid: false,
|
|
15
|
-
error:
|
|
16
|
-
rules?.errorMessages?.maxLength ||
|
|
17
|
-
defaultErrorMessages(rules, type).maxLength,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const defaultRegex =
|
|
22
|
-
rules?.version === 'v4'
|
|
23
|
-
? /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/
|
|
24
|
-
: rules?.version === 'v6'
|
|
25
|
-
? /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/
|
|
26
|
-
: /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$|^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
|
|
27
|
-
const regexToUse = rules?.regex ? new RegExp(rules.regex) : defaultRegex;
|
|
28
|
-
if (!regexToUse.test(value)) {
|
|
29
|
-
return {
|
|
30
|
-
isValid: false,
|
|
31
|
-
error: rules?.errorMessages?.invalid
|
|
32
|
-
? rules?.errorMessages?.invalid
|
|
33
|
-
: defaultErrorMessages(rules, type).ipAddress ||
|
|
34
|
-
defaultErrorMessages(rules, type).invalid,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return { isValid: true, error: '' };
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
module.exports = validateIPAddress;
|