@@ -4,13 +4,12 @@ const defaultErrorMsg: string[] = [
4
4
"Username cannot be empty" ,
5
5
"Username too short" ,
6
6
"This username is too long" ,
7
- "Invalid username" ,
8
7
] ;
9
8
10
9
interface OptionsParams {
11
10
minLength ?: number ;
12
11
maxLength ?: number ;
13
- cbValidate ?: ( username : string ) => boolean ;
12
+ cbValidate ?: ( username : string ) => ValidateFunctions ;
14
13
errorMsg ?: ( string | null ) [ ] ;
15
14
}
16
15
@@ -31,7 +30,7 @@ const defaultOptionsParams: OptionsParams = {
31
30
* @default maxLength number: Infinity
32
31
* @default cbValidate function: undefined
33
32
* @info minLength cannot be greater than maxLength
34
- * @description This function returns 4 errors in the following order,
33
+ * @description This function returns 3 errors in the following order,
35
34
*
36
35
* If you want to use a default parameter, use null.
37
36
*
@@ -40,7 +39,6 @@ const defaultOptionsParams: OptionsParams = {
40
39
"Username cannot be empty",
41
40
"Username must be between ${maxLenthUsername} and ${maxLenthUsername} characters",
42
41
"Username must be between ${maxLenthUsername} and ${maxLenthUsername} characters",
43
- "Invalid username",
44
42
];
45
43
*
46
44
* Create a list of errors separated by commas in strings
@@ -101,16 +99,11 @@ function validateUsername(
101
99
} ;
102
100
}
103
101
104
- if ( cbValidate && ! cbValidate ( username ) ) {
105
- return {
106
- isValid : false ,
107
- errorMsg : getErrorMessage (
108
- 3 ,
109
- errorMsg ,
110
- minLenthUsername ,
111
- maxLenthUsername ,
112
- ) ,
113
- } ;
102
+ const cbValidateResult : ValidateFunctions | undefined =
103
+ cbValidate ?.( username ) ;
104
+
105
+ if ( cbValidateResult && ! cbValidateResult . isValid ) {
106
+ return cbValidateResult ;
114
107
}
115
108
116
109
return {
0 commit comments