From 1c65b5b23725607b2e00e687bdf3b2f3b883dffa Mon Sep 17 00:00:00 2001 From: NCanggoro Date: Wed, 11 Oct 2023 16:31:15 +0700 Subject: [PATCH] handling is string an url --- src/utils/common.ts | 5 +++++ src/utils/index.ts | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/utils/common.ts b/src/utils/common.ts index 4ea548e..d7553b8 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -7,3 +7,8 @@ export function handleAxiosError(error: AxiosError) { export function enumKeys(obj: O): K[] { return Object.keys(obj).filter(k => Number.isNaN(+k)) as K[]; } + +export function isUrl(val: string): boolean { + var urlPattern = /^https:\/\/[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/; + return urlPattern.test(val); +} \ No newline at end of file diff --git a/src/utils/index.ts b/src/utils/index.ts index 49c639a..e8acf60 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,8 +1,9 @@ import useAutosizeTextArea from "./useAutosizeTextArea"; -import { handleAxiosError, enumKeys } from "./common"; +import { handleAxiosError, enumKeys, isUrl } from "./common"; export { useAutosizeTextArea, handleAxiosError, enumKeys, + isUrl } \ No newline at end of file