function isValidURL(url, http) {
  if (http) {
    if (
      /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g.test(
        url
      )
    ) {
      return true
    } else {
      return false
    }
  } else {
    if (
      /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/g.test(
        url
      )
    ) {
      return true
    } else {
      return false
    }
  }
}
Checks if url is valid.

@param {String} url
@param {Boolean}