splitforms.com

Free tool · runs in your browser

URL regex tester

Test website URLs against a strict http(s) regex, a lenient pattern where the scheme is optional, and the browser's own new URL() check, one value per line. Then copy the JavaScript, the HTML pattern attribute or PHP filter_var code.

/^https?:\/\/[^\s/$.?#].\S*$/i

Needs http:// or https:// and a host. Rejects example.com, ftp:, mailto: and javascript:.

6 of 13 pass

ResultValuenew URL() returns
Failexample.comthrows TypeError
Failwww.example.comthrows TypeError
Passhttps://example.comhttps://example.com/
Passhttps://example.com/path?q=1https://example.com/path?q=1
Passhttp://localhost:3000http://localhost:3000/
Passhttps://sub.example.co.uk/a#tophttps://sub.example.co.uk/a#top
PassHTTPS://EXAMPLE.COMhttps://example.com/
Failftp://x.yftp://x.y/not http(s)
Failjavascript:alert(1)javascript:alert(1)not http(s)
Failmailto:hi@example.commailto:hi@example.comnot http(s)
Passhttps://例え.jphttps://xn--r8jz45g.jp/
Failhttps:// space.comthrows TypeError
Fail//example.comthrows TypeError

The HTML pattern has no ^ or $ and no i flag: browsers anchor it to the whole value and match case exactly.

Why type=url accepts javascript: and mailto:

An input type=url is valid when the value parses as an absolute URL, which is close to asking whether new URL(value) throws. Any scheme counts, so javascript:alert(1), mailto:hi@example.com and ftp://x.y all pass. In the tester, javascript:alert(1) fails the strict pattern but passes new URL().

That matters when you show the value as a link: a javascript: URL in an href runs code when clicked. So allow only http and https on the server, where the check can't be skipped:

is-http-url.js

function isHttpUrl(value) {
  try {
    const u = new URL(value.trim());
    return u.protocol === "http:" || u.protocol === "https:";
  } catch {
    return false; // new URL() throws on anything that isn't an absolute URL
  }
}
validate-url.php

$url = trim($_POST['website'] ?? '');
$scheme = strtolower((string) parse_url($url, PHP_URL_SCHEME));
$ok = filter_var($url, FILTER_VALIDATE_URL) !== false
    && in_array($scheme, ['http', 'https'], true);

The HTML website input

website.html

<label for="website">Website</label>
<input type="url" id="website" name="website" pattern="https?://.+" placeholder="https://">

type="url" gives phones a URL keyboard, and the pattern attribute adds the http(s) rule. Browsers anchor the pattern to the whole value, so it has no ^ or $, and it matches case exactly.

Prefill https:// or normalise on the server

Most people type example.com, which type=url rejects. There are two fixes. Prefill the field with https:// so the user types after it, or use a text input with the lenient pattern and add the scheme on the server before you store the value:

normalise.js

function normaliseWebsite(value) {
  const v = value.trim();
  if (v === "") return "";
  return /^[a-z][a-z\d+.-]*:/i.test(v) ? v : `https://${v}`; // "example.com" → "https://example.com"
}

Run the http(s) check after you normalise, not before. A URL that passes every check can still point to a site that doesn't exist; a regex checks format only.

URL regex FAQ

What is a good regex for a URL?

For a website field, ^https?:\/\/[^\s/$.?#].\S*$ with the i flag is a practical choice: it needs http:// or https://, a host and no spaces. No regex fully checks a URL, so for the final check parse it with new URL() and confirm the protocol is http: or https:.

Does input type=url block javascript: links?

No. type=url only checks that the value is an absolute URL, and javascript:alert(1), mailto:hi@example.com and ftp://x.y all are. Add pattern="https?://.+" in the browser, and on the server accept only the http and https schemes.

Should a website field accept example.com without https://?

People often type example.com, and type=url rejects it. Either prefill the field with https:// or use a text input with a scheme-optional pattern, then add https:// on the server before you store or link the value.

How do I validate a URL in PHP?

Use filter_var($url, FILTER_VALIDATE_URL), then read the scheme with parse_url($url, PHP_URL_SCHEME) and allow only http and https, because filter_var accepts other schemes too.

More free form tools

Form backend cost calculator

Enter monthly submissions and compare the cheapest listed plan across eight form backends.

Email deliverability checker

Enter a domain to check its SPF, DMARC and MX records and get a plain-English fix for each.

SPF record checker

Look up a domain's SPF record, see each mechanism explained and count DNS lookups against the 10-lookup limit.

DMARC record generator

Pick a policy and report address and copy a ready _dmarc TXT record.

DMARC checker

Look up a domain's DMARC record and see the policy and every tag explained.

DKIM record checker

Enter a domain and selector to check its DKIM key, with presets for common senders.

SPF record generator

Tick your email providers and copy one SPF TXT record with a lookup count.

Contact form spam checker

Paste form HTML to audit its honeypot, endpoint, CAPTCHA markers and spam resistance.

Honeypot field generator

Generate a hidden anti-spam input with your chosen name and hiding technique.

Form action URL tester

Check a form action URL for reachability, CORS headers, POST acceptance and backend.

Email obfuscator

Encode your email so spam scrapers can't read it but people can still click it.

Mailto link generator

Build a mailto: URL with recipients, CC, BCC, subject and a pre-filled body.

HMAC-SHA256 generator

Generate and verify webhook signatures for common providers in your browser.

URL encoder and decoder

Encode text, build an x-www-form-urlencoded body or parse a query string.

UTM builder

Build campaign URLs with UTM parameters, tag a CSV in bulk and check tagged links.

HTML to JSX converter

Paste HTML and get JSX or a working React/Next.js form component.

Image to Base64 converter

Convert images to Base64 data URLs in your browser and copy HTML and CSS snippets.

Base64 to image converter

Paste a Base64 data URI to preview and download the decoded image.

Base64 decode & encode

Decode Base64 to readable UTF-8 text or encode text to Base64, locally in your browser.

URL to Base64 converter

Fetch a direct image URL in your browser and get its Base64 data URL.

AI form generator

Describe your form in plain English and copy working HTML.

See all free tools