Function isValidUrl

  • Checks if the given string is a valid URL, including scheme URLs.

    Usage:

    const ret1 = isValidUrl('https://www.example.com');
    const ret2 = isValidUrl('http://example.com/path/exx/ss');
    const ret3 = isValidUrl('https://www.example.com/?q=hello&age=24#world');
    const ret4 = isValidUrl('http://www.example.com/#world?id=9');
    const ret5 = isValidUrl('ftp://example.com');
    console.log(ret1, ret2, ret3, ret4, ret5);

    Output:

    true true true true true
    

    Parameters

    • url: string

      The URL to check.

    Returns boolean

    Returns true if the given string is a valid URL, else false.

    Remarks

    If you are specifically checking for HTTP/HTTPS URLs, it is recommended to use the isValidHttpUrl function instead. The isValidUrl function matches all scheme URLs, including FTP and other non-HTTP schemes.