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
| Parameter | Type | Description |
|---|---|---|
|
| The string to validate as a URL. |
| { | Validation options. |
|
| If |
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