@umituz/react-native-validation 1.3.1 → 1.4.0
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/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -21,83 +21,6 @@ export const validateEmail = (email: string): ValidationResult => {
|
|
|
21
21
|
return { isValid: true };
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
/**
|
|
25
|
-
* Validate password strength
|
|
26
|
-
* @param password - Password to validate
|
|
27
|
-
* @param minLength - Minimum password length (default: 8)
|
|
28
|
-
* @param requireUppercase - Require uppercase letter (default: true)
|
|
29
|
-
* @param requireLowercase - Require lowercase letter (default: true)
|
|
30
|
-
* @param requireNumber - Require number (default: true)
|
|
31
|
-
*/
|
|
32
|
-
export const validatePassword = (
|
|
33
|
-
password: string,
|
|
34
|
-
options?: {
|
|
35
|
-
minLength?: number;
|
|
36
|
-
requireUppercase?: boolean;
|
|
37
|
-
requireLowercase?: boolean;
|
|
38
|
-
requireNumber?: boolean;
|
|
39
|
-
}
|
|
40
|
-
): ValidationResult => {
|
|
41
|
-
const {
|
|
42
|
-
minLength = 8,
|
|
43
|
-
requireUppercase = true,
|
|
44
|
-
requireLowercase = true,
|
|
45
|
-
requireNumber = true,
|
|
46
|
-
} = options || {};
|
|
47
|
-
|
|
48
|
-
if (!password || password.trim() === '') {
|
|
49
|
-
return { isValid: false, error: 'Password is required' };
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (password.length < minLength) {
|
|
53
|
-
return {
|
|
54
|
-
isValid: false,
|
|
55
|
-
error: `Password must be at least ${minLength} characters`,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (requireUppercase && !/[A-Z]/.test(password)) {
|
|
60
|
-
return {
|
|
61
|
-
isValid: false,
|
|
62
|
-
error: 'Password must contain at least one uppercase letter',
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (requireLowercase && !/[a-z]/.test(password)) {
|
|
67
|
-
return {
|
|
68
|
-
isValid: false,
|
|
69
|
-
error: 'Password must contain at least one lowercase letter',
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (requireNumber && !/[0-9]/.test(password)) {
|
|
74
|
-
return {
|
|
75
|
-
isValid: false,
|
|
76
|
-
error: 'Password must contain at least one number',
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return { isValid: true };
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Validate password confirmation
|
|
85
|
-
*/
|
|
86
|
-
export const validatePasswordConfirmation = (
|
|
87
|
-
password: string,
|
|
88
|
-
confirmPassword: string
|
|
89
|
-
): ValidationResult => {
|
|
90
|
-
if (!confirmPassword) {
|
|
91
|
-
return { isValid: false, error: 'Please confirm your password' };
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (password !== confirmPassword) {
|
|
95
|
-
return { isValid: false, error: 'Passwords do not match' };
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return { isValid: true };
|
|
99
|
-
};
|
|
100
|
-
|
|
101
24
|
/**
|
|
102
25
|
* Validate required field
|
|
103
26
|
*/
|