(input: string)
| 23 | * @returns `true` if valid, or an error message string if invalid. |
| 24 | */ |
| 25 | export function validateURL(input: string): true | string { |
| 26 | try { |
| 27 | const url = new URL(input); |
| 28 | const protocol = url.protocol.toLowerCase(); |
| 29 | if (protocol !== "http:" && protocol !== "https:") { |
| 30 | return "Please enter a valid URL with http:// or https:// protocol."; |
| 31 | } |
| 32 | return true; |
| 33 | } catch { |
| 34 | return "Please enter a valid URL."; |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Validates that the input is a valid port number (1-65535). |
no outgoing calls
no test coverage detected