Skip to content

Commit

Permalink
utils: add validator functions
Browse files Browse the repository at this point in the history
  • Loading branch information
facuspagnuolo committed Sep 16, 2024
1 parent 91b779d commit e681166
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/validators.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { isAddress } from 'ethers/lib/utils'

export function isValidUrl(url?: string): boolean {
if (typeof url !== 'string') return false
const urlRegex = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-/]))?/
return urlRegex.test(url)
}

export function isValidAddress(address?: string): boolean {
if (typeof address !== 'string') return false
return isAddress(address.toLowerCase())
}

0 comments on commit e681166

Please sign in to comment.