quantique-field-validator 1.0.7 → 1.0.9
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/.github/workflows/publish.yml +31 -0
- package/Messages/defaultErrorMessages.js +27 -26
- package/Validators/ValidateChassisNumber.js +37 -37
- package/Validators/validateAadhaar.js +18 -18
- package/Validators/validateAddress.js +38 -38
- package/Validators/validateAlphanumeric.js +47 -47
- package/Validators/validateBankIFSC.js +41 -41
- package/Validators/validateCustom.js +18 -18
- package/Validators/validateDate.js +166 -166
- package/Validators/validateEmail.js +39 -39
- package/Validators/validateEngineNumber.js +37 -37
- package/Validators/validateFirstMiddleLastName.js +36 -36
- package/Validators/validateFloatNumber.js +108 -108
- package/Validators/validateGST.js +19 -19
- package/Validators/validateIPAddress.js +41 -41
- package/Validators/validateMobile.js +116 -116
- package/Validators/validateName.js +67 -67
- package/Validators/validateNumber.js +75 -75
- package/Validators/validatePanCard.js +23 -23
- package/Validators/validatePassword.js +38 -38
- package/Validators/validateRTO.js +41 -41
- package/Validators/validateString.js +41 -41
- package/index.js +194 -180
- package/package.json +22 -22
|
@@ -1,166 +1,166 @@
|
|
|
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
|
+
// 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 +1,39 @@
|
|
|
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
|
+
// 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 +1,37 @@
|
|
|
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
|
+
// 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 +1,36 @@
|
|
|
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
|
+
// 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;
|