diff --git a/src/app/[locale]/(doc-session)/documentation/js/functions/validateUsername/page.tsx b/src/app/[locale]/(doc-session)/documentation/js/functions/validateUsername/page.tsx
index 81818b5..3b8fd25 100644
--- a/src/app/[locale]/(doc-session)/documentation/js/functions/validateUsername/page.tsx
+++ b/src/app/[locale]/(doc-session)/documentation/js/functions/validateUsername/page.tsx
@@ -54,11 +54,21 @@ export default async function ValidateUsername({
{t("Function Signature")}
-
- {`interface OptionsParams {
+
+ {`type ValidateFunctions =
+ | {
+ isValid: true;
+ errorMsg: null;
+ }
+ | {
+ isValid: false;
+ errorMsg: string;
+ };
+
+interface OptionsParams {
minLength?: number;
maxLength?: number;
- cbValidate?: (username: string) => boolean;
+ cbValidate?: (username: string) => ValidateFunctions;
errorMsg?: (string | null)[];
}
@@ -77,7 +87,7 @@ function validateUsername(
cbValidate,
errorMsg,
}: OptionsParams = defaultOptionsParams,
-): { isValid: boolean, errorMsg: string | null };`}
+): ValidateFunctions {}`}
{t("Parameters")}
@@ -99,9 +109,9 @@ function validateUsername(
)}
- cbValidate
((username: string) -> boolean){" "}
+ cbValidate
((username: string) -> ValidateFunctions){" "}
[optional] - A custom validation function that takes the username as
- an argument and returns a boolean. Default is undefined.
+ an argument and returns a ValidateFunctions. Default is undefined.
errorMsg
(string[]){" "}
@@ -118,7 +128,6 @@ function validateUsername(
"Username cannot be empty",
"Username too short",
"This username is too long",
- "Invalid username",
];`}
@@ -145,7 +154,19 @@ console.log(validateUsername('user123', { minLength: 5, maxLength: 10 }));
// Output: { isValid: true, errorMsg: null }
console.log(validateUsername('user1', {
- cbValidate: (value) => value.length > 5
+ cbValidate: (username: string) => {
+ if (username !== "User123") {
+ return {
+ isValid: false,
+ errorMsg: "Invalid username",
+ };
+ }
+
+ return {
+ isValid: true,
+ errorMsg: null,
+ };
+ },
})); // Output: { isValid: false, errorMsg: 'Invalid username' }`}
diff --git a/src/app/[locale]/(doc-session)/documentation/js/subComponents/MainPageSyntexHightlighter.tsx b/src/app/[locale]/(doc-session)/documentation/js/subComponents/MainPageSyntexHightlighter.tsx
index edcc19f..6c846ae 100644
--- a/src/app/[locale]/(doc-session)/documentation/js/subComponents/MainPageSyntexHightlighter.tsx
+++ b/src/app/[locale]/(doc-session)/documentation/js/subComponents/MainPageSyntexHightlighter.tsx
@@ -68,7 +68,7 @@ export function UsageCDNExample() {
return (
{``}
unpkg
- https://unpkg.com/multiform-validator@2.3.1/dist/cjs/index.cjs
+ https://unpkg.com/multiform-validator@2.4.0/dist/cjs/index.cjs
- {``}
+ {``}
>