Skip to content

Commit

Permalink
Replace custom URL validation with zod
Browse files Browse the repository at this point in the history
  • Loading branch information
AmirAgassi committed Apr 27, 2024
1 parent c13fe5a commit 79c698e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
9 changes: 2 additions & 7 deletions src/components/forms/hackerApplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,10 @@ import {
volunteerSpecificOptions,
} from "@data";
import type { FormInput } from "./types";
import * as z from 'zod';

function isValidUrl(url: string) {
const pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address (you never know!!)
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
'(\\#[-a-z\\d_]*)?$','i'); // fragment locator
return !!pattern.test(url);
return z.string().url().safeParse(url).success;
}

export const hackerAppFormInputs: FormInput[] = [
Expand Down
8 changes: 1 addition & 7 deletions src/pages/Application/Application.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,7 @@ function getLogEventName(component: string) {
}

function isValidUrl(url: string) {
const pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address (you never know!!)
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
'(\\#[-a-z\\d_]*)?$','i'); // fragment locator
return !!pattern.test(url);
return z.string().url().safeParse(url).success;
}

export const ApplicationPage = () => {
Expand Down

0 comments on commit 79c698e

Please sign in to comment.