@regex.to/validators
A curated collection of battle-tested regex patterns with TypeScript types, Zod integration, and multi-language code generation. Zero runtime dependencies.
Installation
Install from npm. Zod is an optional peer dependency for @regex.to/validators/zod:
npm install @regex.to/validators
pnpm add @regex.to/validators
yarn add @regex.to/validators
# with Zod integration
npm install @regex.to/validators zodBasic Usage
import { test, validate, getRegex, PATTERNS } from '@regex.to/validators';
// Quick boolean test
test('email', 'user@example.com'); // → true
test('email', 'not-an-email'); // → false
// Full validation result
const result = validate('email', 'user@example.com');
// → { valid: true, pattern: PatternData, matches: [...] }
// Get the compiled RegExp directly
const re = getRegex('email'); // → /[a-zA-Z0-9._%+\-]+@.../i
// Access the pattern catalog
console.log(PATTERNS['email'].description);Zod Integration
import { zodSchema, zodObjectSchema } from '@regex.to/validators/zod';
import { z } from 'zod';
// Single field schema
const emailSchema = zodSchema('email');
emailSchema.parse('user@example.com'); // ✓ passes
emailSchema.parse('invalid'); // ✗ throws ZodError
// Object schema from field map
const contactSchema = zodObjectSchema({
email: 'email',
website: 'url',
ip: 'ipv4',
});
type ContactForm = z.infer<typeof contactSchema>;detect() — Auto-detect string type
Pass any unknown string and get back an ordered list of matching patterns — full matches (entire string) ranked before partial matches.
import { detect } from '@regex.to/validators';
detect('user@example.com');
// → [{ pattern: { slug: 'email', name: 'Email Address', ... },
// matchType: 'full', matchedText: 'user@example.com', coverage: 1 }]
detect('+14155552671');
// → [{ slug: 'phone-e164', matchType: 'full', coverage: 1 }, ...]
detect('0x742d35Cc6634C0532925a3b844Bc454e4438f44e');
// → [{ slug: 'eth-address', matchType: 'full', coverage: 1 }]Results are sorted by confidence: full matches first, then by coverage ratio. Minimum match length is 4 characters and 20% coverage to filter trivial hits.
API Reference
| Function | Description |
|---|---|
test(slug, value) | Quick boolean match |
validate(slug, value) | Full validation result with matches |
getRegex(slug) | Returns the compiled RegExp |
detect(input) | Auto-detect type of an unknown string |
getAllPatterns() | All patterns as an array |
getByCategory(category) | Filter patterns by category |
getByTags(tags[]) | Filter patterns by tags |
getPattern(slug) | Single pattern by slug, or null |
getSlugs() | All available pattern slugs |
getCategories() | All available category names |
zodSchema(slug, message?) | Zod string schema (zod import) |
zodObjectSchema(fieldMap) | Zod object schema (zod import) |
Patterns (79)
fr-postalFrench Postal Code
Matches a French postal code — exactly 5 digits, starting with 0–9.
de-plzGerman Postal Code (PLZ)
Matches a German postal code (Postleitzahl / PLZ) — exactly 5 digits.
uk-postcodeUK Postcode
Matches a UK postcode in the standard format (e.g. SW1A 1AA, EC1A 1BB).
us-zipUS ZIP Code
Matches a US ZIP code in 5-digit or ZIP+4 (5-4) format.
crypto-mnemonic-wordBIP-39 Mnemonic Phrase
Matches a BIP-39 mnemonic seed phrase — 12, 15, 18, 21, or 24 lowercase English words separated by single spaces.
bitcoin-addressBitcoin Address (Legacy)
Matches a legacy Bitcoin address — P2PKH (starting with 1) or P2SH (starting with 3), 25–34 Base58 characters.
bech32-addressBitcoin Bech32 Address (SegWit)
Matches a Bitcoin native SegWit address in Bech32 format — starts with bc1 followed by 6–87 lowercase alphanumeric characters.
ens-nameENS Name (Ethereum Name Service)
Matches an Ethereum Name Service domain — alphanumeric label(s) ending with .eth.
ethereum-addressEthereum Address
Matches an Ethereum address — 0x followed by exactly 40 hexadecimal characters.
txhash-ethEthereum Transaction Hash
Matches an Ethereum transaction hash — 0x followed by exactly 64 hexadecimal characters.
ipfs-cidIPFS CID
Matches an IPFS Content Identifier (CIDv0 starting with Qm, or CIDv1 starting with bafy/bafk).
lightning-invoiceLightning Network Invoice (BOLT-11)
Matches a Bitcoin Lightning Network payment invoice in BOLT-11 format — starts with lnbc, lntb, or lnbcrt.
monero-addressMonero Address
Matches a Monero (XMR) standard address — starts with 4 and is exactly 95 Base58 characters.
solana-addressSolana Address
Matches a Solana public key — 32–44 Base58 characters (no 0, O, I, l).
date-euDate (European Format)
Matches a European-style date in DD/MM/YYYY, DD.MM.YYYY, or DD-MM-YYYY format.
date-usDate (US Format)
Matches a US-style date in MM/DD/YYYY format.
iso-dateISO 8601 Date
ISO 8601 date format (YYYY-MM-DD) with month and day range validation.
datetime-isoISO 8601 DateTime
Matches an ISO 8601 datetime string with timezone offset or Z (UTC).
time-24hTime (24-hour)
Matches a time in 24-hour format. Supports both HH:MM and HH:MM:SS.
credit-cardCredit Card Number
Generic credit card number validator supporting Visa, Mastercard, American Express, and Discover card formats.
ibanIBAN
Matches an International Bank Account Number (IBAN) — 2-letter country code, 2 check digits, and up to 30 alphanumeric characters.
pl-nipPolish NIP (Tax ID)
Polish NIP (Numer Identyfikacji Podatkowej) — the 10-digit tax identification number used by businesses and self-employed individuals in Poland.
swift-bicSWIFT / BIC Code
Matches a SWIFT/BIC (Bank Identifier Code) — 6-letter institution code + 2-letter country + optional 2-3 character branch.
coordinatesGPS Coordinates
Matches a latitude,longitude coordinate pair separated by a comma.
latitudeLatitude
Matches a geographic latitude coordinate between -90 and +90 degrees, with up to 6 decimal places.
longitudeLongitude
Matches a geographic longitude coordinate between -180 and +180 degrees, with up to 6 decimal places.
au-abnAustralian ABN
Matches an Australian Business Number (ABN) — 11 digits, optionally space-separated in groups.
br-cnpjBrazilian CNPJ
Matches a Brazilian CNPJ (Cadastro Nacional da Pessoa Jurídica) — company identifier in formatted or unformatted form.
br-cpfBrazilian CPF
Matches a Brazilian CPF (Cadastro de Pessoas Físicas) number in formatted (NNN.NNN.NNN-NN) or unformatted (NNNNNNNNNNN) form.
cn-resident-idChinese Resident ID
Matches a Chinese national resident identity card number — 17 digits followed by one digit or X (checksum digit).
fr-sirenFrench SIREN Number
Matches a French SIREN (Système d'Identification du Répertoire des ENtreprises) number — 9 digits.
fr-siretFrench SIRET Number
Matches a French SIRET (Système d'Identification du Répertoire des Établissements) number — 14 digits.
de-steueridGerman Tax ID (Steuer-IdNr)
Matches a German personal tax identification number (Steuerliche Identifikationsnummer) — 11 digits, first digit 1–9.
in-panIndian PAN Card
Matches an Indian Permanent Account Number (PAN) — 10 characters: 5 uppercase letters, 4 digits, 1 uppercase letter.
it-codice-fiscaleItalian Codice Fiscale
Matches an Italian fiscal code (Codice Fiscale) — 16 alphanumeric characters encoding name, birth date, gender, and municipality.
pl-peselPolish PESEL
Polish national identification number (PESEL) — an 11-digit number encoding date of birth, gender, and a checksum, assigned to every citizen.
pl-regonPolish REGON
Matches a Polish REGON (National Business Registry Number) — 9 digits for companies, 14 digits for local units.
ru-innRussian INN (ИНН)
Matches a Russian taxpayer identification number (ИНН) — 10 digits for organisations, 12 digits for individuals.
es-nifSpanish NIF / DNI
Matches a Spanish National Identity Document number (NIF/DNI) — 8 digits followed by a letter, or an NIE starting with X, Y, or Z.
uk-ninoUK National Insurance Number (NINO)
Matches a UK National Insurance Number in the format AA 99 99 99 A.
us-einUS Employer Identification Number (EIN)
Matches a US EIN (Federal Tax ID) in the NN-NNNNNNN format used by the IRS.
us-ssnUS Social Security Number
Matches a US Social Security Number (SSN) in the standard NNN-NN-NNNN format.
domainDomain Name
Matches a valid domain name including subdomains and international TLDs.
emailEmail Address
RFC 5321 compliant email address validation. Supports subdomains, plus-addressing, and international TLDs.
urlURL (HTTP/HTTPS)
Validates HTTP and HTTPS URLs including subdomains, paths, query strings, and anchors.
youtube-urlYouTube Video URL
Matches a YouTube video URL in both youtube.com/watch?v= and youtu.be/ formats and extracts the 11-character video ID.
markdown-blockquoteMarkdown Blockquote
Matches a Markdown blockquote line beginning with > and captures the quoted text.
markdown-boldMarkdown Bold
Matches Markdown bold text wrapped in **double asterisks** or __double underscores__.
markdown-headingMarkdown Heading
Matches Markdown ATX-style headings — # through ###### followed by text. Captures both the level (number of #) and the heading text.
markdown-hrMarkdown Horizontal Rule
Matches a Markdown horizontal rule — three or more dashes, asterisks, or underscores on a line.
markdown-imageMarkdown Image
Matches a Markdown image tag  and captures both the alt text and the URL.
markdown-code-inlineMarkdown Inline Code
Matches Markdown inline code wrapped in single `backticks` or ``double backticks``.
markdown-italicMarkdown Italic
Matches Markdown italic text wrapped in *single asterisk* or _single underscore_.
markdown-list-itemMarkdown List Item
Matches Markdown unordered list items starting with -, *, or + and ordered items starting with a number.
markdown-table-rowMarkdown Table Row
Matches a Markdown GFM table row — cells separated by pipe | characters.
ipv4IPv4 Address
Validates a standard IPv4 address ensuring each octet is 0–255.
ipv6IPv6 Address
Matches a full-form IPv6 address with 8 groups of 4 hexadecimal digits separated by colons.
mac-addressMAC Address
Matches a MAC (Media Access Control) address in both colon-separated and hyphen-separated formats.
port-numberPort Number
Matches a valid TCP/UDP port number from 0 to 65535.
phone-e164Phone — E.164 International
Matches an international phone number in E.164 format: + followed by country code and subscriber number (max 15 digits total).
phone-ukPhone — UK
Matches UK phone numbers in standard formats, starting with 0 or +44.
phone-usPhone — US
Matches a US phone number in various formats: (555) 867-5309, 555-867-5309, 5558675309, or with +1 country code.
base64Base64 Encoded String
Matches a valid Base64-encoded string with proper padding using = characters.
jwtJWT Token
Matches a JSON Web Token (JWT) — three Base64URL-encoded segments separated by dots.
md5MD5 Hash
Matches an MD5 hash — exactly 32 hexadecimal characters.
sha256SHA-256 Hash
Matches a SHA-256 cryptographic hash — exactly 64 hexadecimal characters.
password-strongStrong Password
Matches a strong password: minimum 8 characters with at least one uppercase letter, one lowercase letter, one digit, and one special character.
uuidUUID v4
Matches a UUID version 4 — randomly generated universally unique identifier in the standard 8-4-4-4-12 format.
mention@Mention
Matches a social media @mention — @ followed by 3–30 word characters.
hashtagHashtag
Matches a social media hashtag — # followed by one or more word characters (letters, digits, underscores), starting with a letter.
usernameUsername
Matches a valid username: 3–20 characters, letters, digits, hyphens, and underscores. No leading/trailing hyphens or underscores.
hex-colorHex Color
CSS hex color code in #RGB or #RRGGBB format (case-insensitive).
html-tagHTML Tag
Matches an HTML opening or self-closing tag with optional attributes.
markdown-linkMarkdown Link
Matches a Markdown hyperlink in [text](url) format and captures both the link text and URL.
slugURL Slug
Valid URL slug — lowercase alphanumeric characters separated by single hyphens, no leading or trailing hyphens.
Contributing a Pattern
All patterns are stored as small JSON files. Contributing is a 4-step process:
- 1
Fork the repository
Fork github.com/regex-to/validators and create a branch:
pattern/your-pattern-name - 2
Create the JSON file
json{ "slug": "your-pattern", "name": "Human Readable Name", "description": "What this regex validates.", "category": "Internet", "pattern": "your[regex]pattern+", "flags": "i", "examples": ["valid-input-1", "valid-input-2"], "counterExamples": ["invalid-1"], "tags": ["tag1", "tag2"] } - 3
Test your pattern
bashnpm test # Or paste your pattern into the sandbox at regex.to - 4
Open a Pull Request
Open a PR titled
feat: add [pattern-name] pattern. Patterns are auto-discovered on merge.
Quick CLI Test
node -e "
const { test, detect } = require('@regex.to/validators');
console.log(test('email', 'hello@world.com')); // true
console.log(detect('+48123456789')[0].pattern.slug); // phone-e164
"