MCPcopy Create free account
hub / github.com/PalisadoesFoundation/talawa-api / validateURL

Function validateURL

scripts/setup/validators.ts:25–36  ·  view source on GitHub ↗
(input: string)

Source from the content-addressed store, hash-verified

23 * @returns `true` if valid, or an error message string if invalid.
24 */
25export 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).

Callers 2

validators.test.tsFile · 0.90
apiSetup.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected