aboutsummaryrefslogtreecommitdiff
path: root/utils/validators
diff options
context:
space:
mode:
authorBobby <[email protected]>2025-07-17 12:39:44 +0530
committerBobby <[email protected]>2025-07-17 12:39:44 +0530
commit46e41088bab946856867253c4fa268f9084b86a5 (patch)
tree617b5b31de5b2c0fe0cfd27f29b5580a784d468f /utils/validators
parentb0ba363696a758a8d0637107bd29a0a9ac1382d4 (diff)
downloadimageboard-46e41088bab946856867253c4fa268f9084b86a5.tar.xz
imageboard-46e41088bab946856867253c4fa268f9084b86a5.zip
webp support, decode and transformation functions
Diffstat (limited to 'utils/validators')
-rw-r--r--utils/validators/url.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/utils/validators/url.go b/utils/validators/url.go
new file mode 100644
index 0000000..b85eca7
--- /dev/null
+++ b/utils/validators/url.go
@@ -0,0 +1,26 @@
+package validators
+
+import (
+ "regexp"
+ "strings"
+)
+
+func IsValidURL(url string) bool {
+ if url == "" {
+ return false
+ }
+ if len(url) > 2048 { // Common max URL length
+ return false
+ }
+ if !strings.HasPrefix(url, "http://") && !strings.HasPrefix(url, "https://") {
+ return false
+ }
+
+ pattern := `^(http|https)://[a-zA-Z0-9\-._~:/?#\[\]@!$&'()*+,;=]+$`
+ matched, err := regexp.MatchString(pattern, url)
+ if err != nil {
+ return false
+ }
+
+ return matched
+}