Launching a SaaS?·Collect waitlist signups before you build — before.run
SandboxPatternsDetectDocsChangelog
v1.0.5·MIT License·85 patterns

regex.to/validators

A polyglot regular expression registry. One single source of truth for 85+ patterns (email, URLs, dates, country-specific identifiers, markdown formats), distributed as zero-dependency native packages for your backend or frontend of choice.

Overview

Maintaining custom regex patterns across multiple languages is prone to bugs. `regex.to` solves this by packaging the exact same validated JSON pattern registry into native, optimized libraries for:

  • JavaScript / TypeScript: First-class Zod support and full validation schema.
  • Python: Native, type-hinted package.
  • Go: Advanced PCRE-compatible support using `regexp2` (avoids RE2 lookaround limitations).
  • PHP: Full native PCRE pattern validation.
  • Rust: Fast compiled validation using `fancy-regex` (supports lookarounds).

Each library exposes the exact same unified interface: `validate` (strict full string match), `test` (partial substring match), and `detect` (automatically identify pattern types).

JavaScript / TypeScript (NPM)

Install the `@regexto/validators` package:

bash
npm install @regexto/validators

Usage

typescript
import { validate, test, getRegex } from '@regexto/validators';

// Full validation match
const res = validate('email', 'hello@regex.to'); // { valid: true, ... }

// Fast boolean check
const isUrl = test('url', 'https://regex.to'); // true

// Fetch compiled RegExp object
const rx = getRegex('email'); // /[a-zA-Z0-9...]/

Zod Integration

Import Zod-specific helpers directly:

typescript
import { zodSchema, zodObjectSchema } from '@regexto/validators/zod';
import { z } from 'zod';

const schema = zodObjectSchema({
  email: 'email',
  website: 'url',
});

Python (PyPI)

Install the `regexto-validators` package:

bash
pip install regexto-validators

Usage

python
from regexto_validators import validate, test

# Full validation match
is_valid = validate("email", "hello@regex.to") # True

# Fast boolean check
is_url = test("url", "https://regex.to") # True

Go (pkg.go.dev)

Download the module. Uses PCRE-compatible `regexp2` under the hood:

bash
go get github.com/regex-to/validators-go

Usage

go
package main

import (
    "fmt"
    "github.com/regex-to/validators-go"
)

func main() {
    valid, _ := validators.Validate("email", "hello@regex.to")
    fmt.Println(valid) // true
}

PHP (Packagist)

Require via Composer:

bash
composer require regexto/validators

Usage

php
<?php

use RegexTo\Validators\Validator;

$isValid = Validator::validate('email', 'hello@regex.to'); // true

Rust (Crates.io)

Add to your dependencies. Uses `fancy-regex` to cleanly support patterns with lookarounds:

bash
cargo add regexto-validators

Usage

rust
use regexto_validators::validate;

fn main() {
    let is_valid = validate("email", "hello@regex.to").unwrap();
    println!("Valid? {}", is_valid); // true
}

detect() — Auto-detect string type

Pass any unknown string and get back an ordered list of matching patterns. `detect` is available in all supported languages, utilizing the exact same ranking heuristics.

typescript
// Example showing auto-detection structure
import { detect } from '@regexto/validators';

detect('hello@regex.to');
// → [{ pattern: { slug: 'email', ... }, 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

FunctionDescription
test(slug, value)Quick boolean substring match
validate(slug, value)Full strict match validation
detect(input)Auto-detect type of an unknown string
getAllPatterns()All patterns as an array

Patterns (85)

Identity16 patterns
au-abn

Australian ABN

Matches an Australian Business Number (ABN) — 11 digits, optionally space-separated in groups.

br-cnpj

Brazilian CNPJ

Matches a Brazilian CNPJ (Cadastro Nacional da Pessoa Jurídica) — company identifier in formatted or unformatted form.

br-cpf

Brazilian CPF

Matches a Brazilian CPF (Cadastro de Pessoas Físicas) number in formatted (NNN.NNN.NNN-NN) or unformatted (NNNNNNNNNNN) form.

cn-resident-id

Chinese Resident ID

Matches a Chinese national resident identity card number — 17 digits followed by one digit or X (checksum digit).

fr-siren

French SIREN Number

Matches a French SIREN (Système d'Identification du Répertoire des ENtreprises) number — 9 digits.

fr-siret

French SIRET Number

Matches a French SIRET (Système d'Identification du Répertoire des Établissements) number — 14 digits.

de-steuerid

German Tax ID (Steuer-IdNr)

Matches a German personal tax identification number (Steuerliche Identifikationsnummer) — 11 digits, first digit 1–9.

in-pan

Indian PAN Card

Matches an Indian Permanent Account Number (PAN) — 10 characters: 5 uppercase letters, 4 digits, 1 uppercase letter.

it-codice-fiscale

Italian Codice Fiscale

Matches an Italian fiscal code (Codice Fiscale) — 16 alphanumeric characters encoding name, birth date, gender, and municipality.

pl-pesel

Polish PESEL

Polish national identification number (PESEL) — an 11-digit number encoding date of birth, gender, and a checksum, assigned to every citizen.

pl-regon

Polish REGON

Matches a Polish REGON (National Business Registry Number) — 9 digits for companies, 14 digits for local units.

ru-inn

Russian INN (ИНН)

Matches a Russian taxpayer identification number (ИНН) — 10 digits for organisations, 12 digits for individuals.

es-nif

Spanish 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-nino

UK National Insurance Number (NINO)

Matches a UK National Insurance Number in the format AA 99 99 99 A.

us-ein

US Employer Identification Number (EIN)

Matches a US EIN (Federal Tax ID) in the NN-NNNNNNN format used by the IRS.

us-ssn

US Social Security Number

Matches a US Social Security Number (SSN) in the standard NNN-NN-NNNN format.

Contributing a Pattern

All patterns are stored as small JSON files. Contributing is a 4-step process:

  1. 1

    Fork the repository

    Fork github.com/regex-to/validators and create a branch: pattern/your-pattern-name

  2. 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. 3

    Test your pattern

    bash
    npm test
    # Or paste your pattern into the sandbox at regex.to
  4. 4

    Open a Pull Request

    Open a PR titled feat: add [pattern-name] pattern. Patterns are auto-discovered on merge.