# ivyforms/0.5/frontend/src/utils/url.ts

The Innovative Form Builder – IvyForms, version 0.5. 30 lines.

- Page: https://pluginprobe.com/plugins/ivyforms/0.5/code/frontend/src/utils/url.ts
- Raw: https://pluginprobe.com/plugins/ivyforms/0.5/raw/frontend/src/utils/url.ts
- Modified: 2025-10-23T15:35:44+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/ivyforms/0.5/code/frontend/src/utils/url.ts#L10-L20`.

```typescript
// URL validation utility

/**
 * Checks if a string is a valid URL for the form builder.
 * Allows domains, localhost, IPv4, IPv6, with optional port and path.
 * Disallows multiple protocols and garbage before the URL.
 */
export function isValidUrl(urlInput: string): boolean {
  if (!urlInput) return false
  const url = urlInput.trim()
  // Allow domains, localhost, IPv4, IPv6
  const startPattern =
    /^(https?:\/\/)?([a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*|localhost|\d{1,3}(\.\d{1,3}){3}|\[[0-9a-fA-F:]+\])(:\d+)?(\/|$)/
  if (!startPattern.test(url)) return false
  // Disallow protocol more than once
  const protocolMatches = url.match(/https?:\/\//gi)
  if (protocolMatches && protocolMatches.length > 1) return false
  // Use URL constructor for validation
  let urlToTest = url
  try {
    if (!/^https?:\/\//i.test(url)) {
      urlToTest = 'https://' + url
    }
    new URL(urlToTest)
    return true
  } catch {
    return false
  }
}

```
