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
| Result | Value | new URL() returns |
|---|---|---|
| Fail | example.com | throws TypeError |
| Fail | www.example.com | throws TypeError |
| Pass | https://example.com | https://example.com/ |
| Pass | https://example.com/path?q=1 | https://example.com/path?q=1 |
| Pass | http://localhost:3000 | http://localhost:3000/ |
| Pass | https://sub.example.co.uk/a#top | https://sub.example.co.uk/a#top |
| Pass | HTTPS://EXAMPLE.COM | https://example.com/ |
| Fail | ftp://x.y | ftp://x.y/not http(s) |
| Fail | javascript:alert(1) | javascript:alert(1)not http(s) |
| Fail | mailto:hi@example.com | mailto:hi@example.comnot http(s) |
| Pass | https://例え.jp | https://xn--r8jz45g.jp/ |
| Fail | https:// space.com | throws TypeError |
| Fail | //example.com | throws 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:
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
}
}$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
<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:
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.
Regex patterns for form fields
Alphanumeric regex tester
Test letters and numbers, spaces, handles and Unicode patterns.
Email regex tester
Test email patterns against edge cases and your own list.
Phone number regex tester
Check numbers against E.164, US/Canada and digits-only patterns.
Password regex generator
Pick strength rules and copy the regex or HTML pattern.
ZIP code regex
US ZIP, ZIP+4, Canadian and UK postal code patterns.
Number regex tester
Test digits, decimals, money and thousands separators.
Date regex tester
Date formats, strict ranges and leap-year aware ISO patterns.
Name regex tester
Validate names with accents, hyphens and apostrophes.
Username regex tester
Test username length, separators and reserved names.
IP address regex tester
Validate IPv4, IPv6 and CIDR input with strict octets.
HTML pattern attribute
How browsers anchor and check a pattern on an input.
HTML required attribute
Stop a form from sending while a field is empty.
Validate a form with JavaScript
Use checkValidity, custom messages and your own rules.
Time regex tester
Validate 24-hour, AM/PM and ISO 8601 time formats.
Credit card regex tester
Match card brands by prefix and length, then run a Luhn check.
Hex color regex tester
Match hex, rgb() and hsl() colors with range checks and swatches.
UUID regex tester
Match UUID v4, v7 and GUIDs with version and variant checks.
Use your validation patterns as you assemble a form with our HTML contact form code or HTML form generator.
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.