quantique-field-validator 1.0.5-beta → 1.0.6
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.
|
@@ -8,7 +8,7 @@ const validateGST = (value, rules, defaultErrorMessages, type) => {
|
|
|
8
8
|
isValid: false,
|
|
9
9
|
error:
|
|
10
10
|
rules?.errorMessages?.regex ||
|
|
11
|
-
"Please
|
|
11
|
+
"Please entere a valid GSTIN number" ||
|
|
12
12
|
defaultErrorMessages(rules, type).invalid,
|
|
13
13
|
};
|
|
14
14
|
}
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
// Name validation
|
|
2
2
|
const validateName = (
|
|
3
3
|
value,
|
|
4
|
-
rules = { type:
|
|
4
|
+
rules = { type: 'user' },
|
|
5
5
|
defaultErrorMessages,
|
|
6
6
|
type
|
|
7
7
|
) => {
|
|
8
|
+
// First check if value is empty or just whitespace
|
|
9
|
+
if (!value || !value.trim()) {
|
|
10
|
+
return {
|
|
11
|
+
isValid: false,
|
|
12
|
+
error: rules?.errorMessages?.empty || 'Name cannot be empty',
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
8
16
|
// Check length constraints
|
|
9
17
|
if (rules?.minLength && value?.length < rules?.minLength) {
|
|
10
18
|
return {
|
|
@@ -26,21 +34,21 @@ const validateName = (
|
|
|
26
34
|
|
|
27
35
|
// Default name validation (only letters, spaces, and basic punctuation)
|
|
28
36
|
// Check against custom regex if provided
|
|
29
|
-
if (rules?.type ===
|
|
30
|
-
const defaultRegex = /^[a-zA-ZÀ-ÿ\s'-.]*$/;
|
|
37
|
+
if (rules?.type === 'user') {
|
|
38
|
+
const defaultRegex = /^(?=.*[a-zA-ZÀ-ÿ])[a-zA-ZÀ-ÿ\s'-.]*$/;
|
|
31
39
|
const regexToUse = rules?.regex ? new RegExp(rules.regex) : defaultRegex;
|
|
32
40
|
|
|
33
41
|
if (!regexToUse.test(value)) {
|
|
34
42
|
return {
|
|
35
43
|
isValid: false,
|
|
36
44
|
error:
|
|
37
|
-
rules?.errorMessages?.invalid ||
|
|
45
|
+
rules?.errorMessages?.invalid || 'Name contains invalid characters',
|
|
38
46
|
};
|
|
39
47
|
}
|
|
40
48
|
}
|
|
41
49
|
|
|
42
|
-
if (rules?.type ===
|
|
43
|
-
const defaultRegex = /^[A-Za-z0-9&.,'()\- ]*$/;
|
|
50
|
+
if (rules?.type === 'corporate') {
|
|
51
|
+
const defaultRegex = /^(?=.*[A-Za-z0-9])[A-Za-z0-9&.,'()\- ]*$/;
|
|
44
52
|
const regexToUse = rules?.regex ? new RegExp(rules.regex) : defaultRegex;
|
|
45
53
|
|
|
46
54
|
if (!regexToUse.test(value)) {
|
|
@@ -48,12 +56,12 @@ const validateName = (
|
|
|
48
56
|
isValid: false,
|
|
49
57
|
error:
|
|
50
58
|
rules?.errorMessages?.invalid ||
|
|
51
|
-
|
|
59
|
+
'Corporate Name contains invalid characters',
|
|
52
60
|
};
|
|
53
61
|
}
|
|
54
62
|
}
|
|
55
63
|
|
|
56
|
-
return { isValid: true, error:
|
|
64
|
+
return { isValid: true, error: '' };
|
|
57
65
|
};
|
|
58
66
|
|
|
59
67
|
module.exports = validateName;
|
|
@@ -4,27 +4,16 @@ const validatePanCard = (
|
|
|
4
4
|
defaultErrorMessages,
|
|
5
5
|
type
|
|
6
6
|
) => {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
};
|
|
7
|
+
const defaultRegex = /^[A-Z]{5}[0-9]{4}[A-Z]{1}$/;
|
|
8
|
+
const regexToUse = rules?.regex ? new RegExp(rules.regex) : defaultRegex;
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
const effectiveRules = {
|
|
13
|
-
...defaultRules,
|
|
14
|
-
...rules,
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (
|
|
20
|
-
effectiveRules?.regex &&
|
|
21
|
-
!new RegExp(effectiveRules?.regex).test(value)
|
|
22
|
-
) {
|
|
10
|
+
if (!regexToUse.test(value)) {
|
|
23
11
|
return {
|
|
24
12
|
isValid: false,
|
|
25
13
|
error:
|
|
26
|
-
|
|
27
|
-
|
|
14
|
+
rules?.errorMessages?.regex ||
|
|
15
|
+
rules?.errorMessages?.invalid ||
|
|
16
|
+
defaultErrorMessages(rules, type).invalid,
|
|
28
17
|
};
|
|
29
18
|
}
|
|
30
19
|
|