splitforms.com

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

  • PassO'Brien
  • PassJean-Luc
  • PassJosé María
  • PassZoë
  • PassNguyễn
  • Pass李小龙
  • FailX Æ A-12
  • PassMr. T
  • Fail
  • Faila1
  • Fail<script>
  • PassA

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.

PresetRegexPass / fail examplesNotes
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 Luc
Fail: 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, A
Fail: 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

name.html

<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

validate-name.js

const NAME_RE = new RegExp("^[\\p{L}\\p{M}][\\p{L}\\p{M}' .-]*$", "u");
const ok = NAME_RE.test(value.trim());
validate-name.php

$name = trim($_POST['name'] ?? '');
$ok = preg_match('/^[\p{L}\p{M}][\p{L}\p{M}\' .-]*$/u', $name) === 1;
validate-name.py

# 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 None

Always 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.

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