Skip to content

Utils / Full Stack / isUrl

Function: isUrl()

ts
function isUrl(string, options?): boolean;

Validates if the given string is a valid URL.

A valid URL includes a protocol (e.g., http, https) and conforms to the URL standard. If the lenient option is enabled, it will attempt to prepend https:// to the input if it fails the initial check.

Parameters

ParameterTypeDescription

string

string

The string to validate as a URL.

options

{ lenient?: boolean; }

Validation options.

options.lenient?

boolean

If true, tries to prepend https:// to the input for lenient validation (default: false).

Returns

boolean

true if the string is a valid URL, otherwise false.

Throws

TypeError if the input is not a string.

Example

typescript
isUrl("https://example.com"); // true
isUrl("example.com", { lenient: true }); // true
isUrl("invalid url"); // false

Version v1.33.1 - Built on 2026-03-28