Skip to main content

Function: isUrl()

isUrl(str): Option<string>

Defined in: string/validators/index.ts:118

Validates if a string is a valid URL.

Returns Some with the URL if valid, None otherwise. Supports http, https, and protocol-relative URLs.

Parameters

str

string

The string to validate

Returns

Option<string>

Option containing the URL if valid

Example

isUrl('https://example.com')
// => Some('https://example.com')

isUrl('not a url')
// => None

isUrl('http://localhost:3000/path')
// => Some('http://localhost:3000/path')

// Use in validation
const website = pipe(
formData.website,
isUrl,
match({
onSome: (url) => url,
onNone: () => 'Invalid URL'
})
)

See

isEmail - for email validation