Free tool · runs in your browser
Name regex tester
Test full-name patterns for O'Brien, Jean-Luc, accents and Unicode letters. Pick a preset, edit the regex, paste names one per line, then copy JavaScript or an HTML pattern snippet.
Unicode letters (\p{L}) and marks (\p{M}); apostrophe, space, dot and hyphen after the first letter. Single-character and single-word names are allowed. Use the u flag in JavaScript and PHP.
8 of 12 pass
- Pass
O'Brien - Pass
Jean-Luc - Pass
José María - Pass
Zoë - Pass
Nguyễn - Pass
李小龙 - Fail
X Æ A-12 - Pass
Mr. T - Fail
- Fail
a1 - Fail
<script> - Pass
A
HTML pattern is checked with the v flag in modern browsers; escape - inside character classes. Trim and length-limit on the server.
Why strict name regex is a bad idea
Names vary by culture, language and legal ID. A single ASCII regex cannot represent personal names around the world. Use regex only to catch obvious typos, then trim and length-limit instead of over-validating (for example maxlength="100" and required).
Recommended pattern
Default preset: ^[\p{L}\p{M}][\p{L}\p{M}' .-]*$ with new RegExp(..., "u"). Allows one-character names, single-word names, apostrophes and hyphens.
| Preset | Regex | Pass / fail examples | Notes |
|---|---|---|---|
| Permissive (recommended) | ^[\p{L}\p{M}][\p{L}\p{M}' .-]*$ | Pass: O'Brien, Jean-Luc, José María, Zoë, Nguyễn, 李小龙, Mr. T, A, JoséFail: X Æ A-12, , a1, <script> | Unicode letters (\p{L}) and marks (\p{M}); apostrophe, space, dot and hyphen after the first letter. Single-character and single-word names are allowed. Use the u flag in JavaScript and PHP. |
| Latin letters + accents | ^[A-Za-zÀ-ÖØ-öø-ÿ' -]+$ | Pass: O'Brien, Jean-Luc, José María, ZoëFail: Mr. T, Nguyễn, 李小龙, X Æ A-12, a1, <script> | Western letters and common accented Latin ranges only. CJK and other scripts fail. Trim whitespace before matching; a spaces-only value can match this pattern. |
| First + last name required | ^[\p{L}\p{M}][\p{L}\p{M}' .-]* [\p{L}\p{M}][\p{L}\p{M}' .-]*$ | Pass: José María, Mary Jane, Jean LucFail: O'Brien, Jean-Luc, 李小龙, A, , a1, <script> | At least one ASCII space between two name parts. Hyphenated single tokens such as Jean-Luc do not count as two names. |
| ASCII only (strict, not recommended) | ^[A-Za-z][A-Za-z' \-]*$ | Pass: O'Brien, Jean-Luc, AFail: Mr. T, José, Zoë, Nguyễn, 李小龙, José María, X Æ A-12, a1, <script> | A–Z only. Rejects most real names outside basic English. Prefer the permissive Unicode pattern instead. |
HTML name input
<label for="name">Full name</label>
<input id="name" name="name" type="text" autocomplete="name" pattern="[\p{L}\p{M}][\p{L}\p{M}' .\-]*" title="Letters; apostrophe, space, dot or hyphen allowed after the first letter" maxlength="100" required>Use autocomplete="name" for autofill and the pattern attribute without ^ or $ (the browser anchors the whole value). Pair with required and maxlength.
Validate on the server too
const NAME_RE = new RegExp("^[\\p{L}\\p{M}][\\p{L}\\p{M}' .-]*$", "u");
const ok = NAME_RE.test(value.trim());$name = trim($_POST['name'] ?? '');
$ok = preg_match('/^[\p{L}\p{M}][\p{L}\p{M}\' .-]*$/u', $name) === 1;# pip install regex (\p{L} support)
import regex
NAME_RE = regex.compile(r"[\p{L}\p{M}][\p{L}\p{M}' .-]*")
ok = NAME_RE.fullmatch(name.strip()) is not NoneAlways trim() first, enforce a generous max length, and treat regex as a hint—not proof of a real person.
Name regex FAQ
What regex validates a person’s name with an apostrophe?
Use ^[\p{L}\p{M}][\p{L}\p{M}' .-]*$ with the u flag so O'Brien and D'Angelo pass. The first character must be a letter or mark; later characters may include apostrophe, space, dot or hyphen.
Should I require first and last name in the regex?
Usually no. Many people use one name, initials or multiple family names. If you need two parts for shipping labels, use a separate field or a looser rule (at least one space) and still allow overrides.
Does HTML pattern support \p{L} Unicode letters?
Modern browsers compile pattern with the v flag and accept \p{L} and \p{M}. Escape hyphens inside classes. Older browsers may ignore pattern; always validate again on the server.
Why is a strict ASCII name regex a bad idea?
Real names use accents (José, Zoë), scripts beyond A–Z (李小龙) and punctuation cultures expect (hyphens, apostrophes). Over-tight regex rejects paying customers; trim, maxlength and human review catch abuse better.
Can I block XSS with a name regex?
No. <script> should fail because < is not allowed, but regex is not a security boundary. Escape on output, use CSP and validate length; never rely on pattern alone for safety.
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.
Username regex tester
Test username length, separators and reserved names.
IP address regex tester
Validate IPv4, IPv6 and CIDR input with strict octets.
URL regex tester
Check website fields with regex, type=url or new URL().
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.