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
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
name: Publish Package to npm
|
|
2
|
+
|
|
3
|
+
# This tells GitHub to run this script whenever you publish a new Release on GitHub
|
|
4
|
+
on:
|
|
5
|
+
release:
|
|
6
|
+
types: [published]
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
publish-npm:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- name: Checkout code
|
|
13
|
+
uses: actions/checkout@v4
|
|
14
|
+
|
|
15
|
+
# Setup Node.js (I set this to v24 to match the version in your error logs)
|
|
16
|
+
- name: Setup Node.js
|
|
17
|
+
uses: actions/setup-node@v4
|
|
18
|
+
with:
|
|
19
|
+
node-version: '24.x'
|
|
20
|
+
registry-url: 'https://registry.npmjs.org'
|
|
21
|
+
|
|
22
|
+
# Install dependencies cleanly
|
|
23
|
+
- name: Install dependencies
|
|
24
|
+
run: npm ci
|
|
25
|
+
|
|
26
|
+
# Publish the package
|
|
27
|
+
- name: Publish to npm
|
|
28
|
+
run: npm publish --tag beta
|
|
29
|
+
env:
|
|
30
|
+
# This pulls the token we saved in Step 2 securely
|
|
31
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
@@ -1,26 +1,27 @@
|
|
|
1
|
-
// Default error messages
|
|
2
|
-
const defaultErrorMessages = (rules, type) => {
|
|
3
|
-
return {
|
|
4
|
-
noSpace: "Value should not contain spaces",
|
|
5
|
-
minAge: `User must be ${rules.minAge} years or older`,
|
|
6
|
-
minMinus: "Date is too far in the past",
|
|
7
|
-
maxPlus: "Date is too far in the future",
|
|
8
|
-
required: "This field is required",
|
|
9
|
-
minLength: `Minimum length should be ${rules.minLength}`,
|
|
10
|
-
maxLength: `Maximum length should be ${rules.maxLength}`,
|
|
11
|
-
invalid: `Please entere a valid ${type}`,
|
|
12
|
-
noValidation: `No validation exist for ${type}`,
|
|
13
|
-
custom: "Validation failed",
|
|
14
|
-
Alphanumeric: "value must be alphanumeric",
|
|
15
|
-
chassisNumber: "Invalid chassis number",
|
|
16
|
-
engineNumber: "Invalid engine number",
|
|
17
|
-
ipAddress: "Invalid IP Address",
|
|
18
|
-
name: "Invalid name",
|
|
19
|
-
rto: "Invalid RTO",
|
|
20
|
-
ifsc: "Invalid Bank IFSC Code",
|
|
21
|
-
customValidation:
|
|
22
|
-
rules.errorMessages?.customValidation || "Custom validation failed",
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
|
|
1
|
+
// Default error messages
|
|
2
|
+
const defaultErrorMessages = (rules, type) => {
|
|
3
|
+
return {
|
|
4
|
+
noSpace: "Value should not contain spaces",
|
|
5
|
+
minAge: `User must be ${rules.minAge} years or older`,
|
|
6
|
+
minMinus: "Date is too far in the past",
|
|
7
|
+
maxPlus: "Date is too far in the future",
|
|
8
|
+
required: "This field is required",
|
|
9
|
+
minLength: `Minimum length should be ${rules.minLength}`,
|
|
10
|
+
maxLength: `Maximum length should be ${rules.maxLength}`,
|
|
11
|
+
invalid: `Please entere a valid ${type}`,
|
|
12
|
+
noValidation: `No validation exist for ${type}`,
|
|
13
|
+
custom: "Validation failed",
|
|
14
|
+
Alphanumeric: "value must be alphanumeric",
|
|
15
|
+
chassisNumber: "Invalid chassis number",
|
|
16
|
+
engineNumber: "Invalid engine number",
|
|
17
|
+
ipAddress: "Invalid IP Address",
|
|
18
|
+
name: "Invalid name",
|
|
19
|
+
rto: "Invalid RTO",
|
|
20
|
+
ifsc: "Invalid Bank IFSC Code",
|
|
21
|
+
customValidation:
|
|
22
|
+
rules.errorMessages?.customValidation || "Custom validation failed",
|
|
23
|
+
emoji: "Emoji characters are not allowed",
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
module.exports = defaultErrorMessages;
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
// ChassisNumber validation
|
|
2
|
-
const validateChassisNumber = (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-HJ-NPR-Z])[A-HJ-NPR-Z0-9]{17}$/;
|
|
22
|
-
const regexToUse = rules?.regex ? new RegExp(rules.regex) : defaultRegex;
|
|
23
|
-
console.log(regexToUse);
|
|
24
|
-
if (!regexToUse.test(value)) {
|
|
25
|
-
return {
|
|
26
|
-
isValid: false,
|
|
27
|
-
error: rules?.errorMessages?.invalid
|
|
28
|
-
? rules?.errorMessages?.invalid
|
|
29
|
-
: defaultErrorMessages(rules, type).chassisNumber ||
|
|
30
|
-
defaultErrorMessages(rules, type).invalid,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return { isValid: true, error: "" };
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
module.exports = validateChassisNumber;
|
|
1
|
+
// ChassisNumber validation
|
|
2
|
+
const validateChassisNumber = (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-HJ-NPR-Z])[A-HJ-NPR-Z0-9]{17}$/;
|
|
22
|
+
const regexToUse = rules?.regex ? new RegExp(rules.regex) : defaultRegex;
|
|
23
|
+
console.log(regexToUse);
|
|
24
|
+
if (!regexToUse.test(value)) {
|
|
25
|
+
return {
|
|
26
|
+
isValid: false,
|
|
27
|
+
error: rules?.errorMessages?.invalid
|
|
28
|
+
? rules?.errorMessages?.invalid
|
|
29
|
+
: defaultErrorMessages(rules, type).chassisNumber ||
|
|
30
|
+
defaultErrorMessages(rules, type).invalid,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return { isValid: true, error: "" };
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
module.exports = validateChassisNumber;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
const validateAadhaar = (value, rules, defaultErrorMessages, type) => {
|
|
2
|
-
const defaultRegex = /^[2-9]{1}[0-9]{11}$/;
|
|
3
|
-
const regexToUse = rules?.regex ? new RegExp(rules.regex) : defaultRegex;
|
|
4
|
-
|
|
5
|
-
if (!regexToUse.test(value)) {
|
|
6
|
-
return {
|
|
7
|
-
isValid: false,
|
|
8
|
-
error:
|
|
9
|
-
rules?.errorMessages?.regex ||
|
|
10
|
-
rules?.errorMessages?.invalid ||
|
|
11
|
-
defaultErrorMessages(rules, type).invalid,
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return { isValid: true, error: "" };
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
module.exports = validateAadhaar;
|
|
1
|
+
const validateAadhaar = (value, rules, defaultErrorMessages, type) => {
|
|
2
|
+
const defaultRegex = /^[2-9]{1}[0-9]{11}$/;
|
|
3
|
+
const regexToUse = rules?.regex ? new RegExp(rules.regex) : defaultRegex;
|
|
4
|
+
|
|
5
|
+
if (!regexToUse.test(value)) {
|
|
6
|
+
return {
|
|
7
|
+
isValid: false,
|
|
8
|
+
error:
|
|
9
|
+
rules?.errorMessages?.regex ||
|
|
10
|
+
rules?.errorMessages?.invalid ||
|
|
11
|
+
defaultErrorMessages(rules, type).invalid,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return { isValid: true, error: "" };
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
module.exports = validateAadhaar;
|
|
@@ -1,38 +1,38 @@
|
|
|
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
|
+
// 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 +1,47 @@
|
|
|
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
|
+
// 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 +1,41 @@
|
|
|
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
|
+
//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 +1,18 @@
|
|
|
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
|
+
// 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;
|