Skip to content

isURL

The isURL function checks if a string matches the format of a valid URL (http or https).

Syntax

javascript
isURL(value)

Parameters

ParameterTypeDescription
valuestringURL to be checked.

Return

TypeDescription
booleanReturns true if the string matches the format of a valid URL, otherwise returns false.

Examples

javascript
isURL('https://www.example.com');      // true
isURL('http://example.com/path');      // true
isURL('ftp://example.com');            // false
isURL('www.example.com');              // false
isURL('https://example');              // false
isURL('https://example.com:8080');     // true
isURL('https://example.com/path?q=1'); // true
isURL('');                            // false

Notes

  • Throws a TypeError if the provided value is not a string.
  • Only validates URLs with http or https protocol.

References

Released under the MIT License.