Developer tooling

Form Validation Regex Builder

Pick a common field type and get its regex, a plain-English explanation, and a live tester — ready to copy as JavaScript or an HTML5 pattern attribute.

Everything runs locally — nothing you type is sent anywhere.

📋

11 ready-made presets

Email, phone, URL, password, IPv4, ISO date, slug and more, each explained in plain English.

Test as you type

The input field turns green or red instantly so you can confirm a pattern behaves the way you expect.

📋

Two copy formats

Copy the raw JavaScript-ready regex, or an HTML5 <input pattern> tag with the anchors already removed.

How to use the regex builder

Pick a preset, read what it enforces, then test and copy it.

  1. Choose a field typeClick a chip like Email, URL or Strong password to load its pattern.
  2. Read the explanationEach preset includes a plain-English description of exactly what it requires and rejects.
  3. Test and copyType sample text into the tester, then copy the regex or the ready-made HTML5 pattern attribute.

Regex validation basics

Regular expressions describe a shape that a string either matches or doesn't. In JavaScript that shape is usually anchored with ^ at the start and $ at the end so a partial match in the middle of a longer string doesn't count as valid. The HTML5 pattern attribute works differently: the browser always anchors it to the whole value automatically, which is why the copyable input snippet here strips the ^ and $ characters rather than leaving them in, where they would otherwise be treated as literal characters to match.

Lookaheads

Groups like (?=.*[A-Z]) check that a condition exists somewhere ahead without consuming characters, letting several rules combine, as in the strong password preset.

Character classes

Sets like [0-9A-Fa-f] or \d describe one allowed character at a time; repeating them with {n} or + controls how many are required.

Anchoring

Without ^ and $, a JavaScript regex can match anywhere inside a string, which usually isn't what you want for whole-field validation.

Client vs. server

Client-side patterns improve the experience, but the same rule should always be enforced again on the server, since client-side checks can be bypassed.

Form validation regex builder FAQ

Questions about anchoring, edge cases and the tester.

Why doesn't the HTML5 pattern attribute need ^ and $?

The pattern attribute on an <input> is automatically anchored to match the entire value, so ^ and $ are not needed and are actually invalid in that context. This tool's copy button for the pattern snippet already strips them for you.

Are these regexes perfect for every edge case?

No single short regex perfectly validates something like every real email address or phone number in existence. These presets cover the common, practical cases well and are meant as a solid starting point, not a replacement for server-side validation.

Can I test my own text against a preset?

Yes. Once you pick a preset, type into the test field below it and the border turns green for a match or red for no match as you type.

Why does the strong password pattern use (?=...) groups?

Those are lookaheads. Each one checks for a required character class (a lowercase letter, an uppercase letter, a digit, a symbol) without consuming characters, which lets several independent conditions be enforced on the same string alongside a minimum length.

Is anything I type sent anywhere?

No. Every pattern match happens locally in your browser using JavaScript's built-in regular expression engine. Nothing you type in the tester is transmitted or stored.