Move to TanStack Start from Next.js (#184)

This commit is contained in:
Aslam
2024-10-07 16:44:17 +07:00
committed by GitHub
parent 3a89a1c07f
commit 950ebc3dad
514 changed files with 20021 additions and 15508 deletions

View File

@@ -0,0 +1,43 @@
/*
* This file contains custom schema definitions for Zod.
*/
import { z } from "zod"
export const urlSchema = z
.string()
.min(1, { message: "URL can't be empty" })
.refine(
(value) => {
const domainRegex =
/^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/
const isValidDomain = (domain: string) => {
try {
const url = new URL(`http://${domain}`)
return domainRegex.test(url.hostname)
} catch {
return false
}
}
if (isValidDomain(value)) {
return true
}
try {
const url = new URL(value)
if (!url.protocol.match(/^https?:$/)) {
return false
}
return isValidDomain(url.hostname)
} catch {
return false
}
},
{
message: "Please enter a valid URL",
},
)