Function isValidHttpUrl

  • Check if the given string is a valid HTTP/HTTPS URL.

    Usage:

    const ret1 = isValidHttpUrl('https://www.example.com');
    const ret2 = isValidHttpUrl('http://example.com/path/exx/ss');
    const ret3 = isValidHttpUrl('https://www.example.com/?q=hello&age=24#world');
    const ret4 = isValidHttpUrl('http://www.example.com/#world?id=9');
    const ret5 = isValidHttpUrl('//example.com/a/b/c?q=1', { strict: false });
    const ret6 = isValidHttpUrl('ftp://example.com');
    console.log(ret1, ret2, ret3, ret4, ret5, ret6);

    Output:

    true true true true true false
    

    Parameters

    • url: string
    • options: {
          strict: boolean;
      } = ...
      • strict: boolean

        If true, the function only matches standard HTTP/HTTPS URLs. Default is true. If false, the function also matches protocol-relative URLs, such as //example.com.

    Returns boolean

    Return true if the given string is a valid HTTP/HTTPS URL.