@regexto/validators
v1.0.3
Published
A curated collection of battle-tested regex patterns with TypeScript types, Zod integration, and multi-language code generation.
Downloads
479
Maintainers
Readme
📦 @regexto/validators
Curated, production-ready, and battle-tested regex patterns with native TypeScript support, Zod integration, and multi-language compilation.
All patterns are open-source, fully tested, and visualized live on regex.to.
Why @regexto/validators?
- 🔍 Tested and Visualized Live: Every single pattern in this library can be searched, tested, and visualized interactively at regex.to.
- 🚀 Zero Dependencies: Pure JavaScript/TypeScript validator package. Lightweight and lightning-fast.
- 🛠️ Zod v4 Ready: Built-in integration for type-safe form schema validation out of the box.
- 📁 JSON Single Source of Truth: Patterns are declared declaratively in standard JSON files.
Installation
npm install @regexto/validators
# Optional: if you use Zod validation
npm install zodQuick Start
1. Basic Validation (JavaScript / TypeScript)
import { test, validate, getRegex } from '@regexto/validators';
// 1. Quick boolean test
test('email', '[email protected]'); // → true
test('email', 'invalid-email'); // → false
// 2. Full validation with capture group outputs
const result = validate('ipv4', '192.168.1.1');
console.log(result.valid); // → true
// 3. Extract the raw RegExp instance
const emailRegex = getRegex('email'); // → RegExp instance2. Type-Safe Zod Schema Integration
import { z } from 'zod';
import { zodSchema, zodObjectSchema } from '@regexto/validators/zod';
// Create a single-field validator schema
const emailValidator = zodSchema('email');
emailValidator.parse('[email protected]'); // ✓ Valid
// Easily construct object validation shapes
const registrationSchema = zodObjectSchema({
email: 'email',
website: 'url',
zipCode: 'us-zip',
});
type RegistrationData = z.infer<typeof registrationSchema>;3. Smart Type Auto-Detection
Pass an unknown string, and the validator will identify matching formats:
import { detect } from '@regexto/validators';
const matches = detect('0x742d35Cc6634C0532925a3b844Bc454e4438f44e');
// → [{ pattern: { slug: 'ethereum-address', ... }, matchType: 'full', coverage: 1 }]Available Patterns
Here is a curated subset of the 79+ patterns supported. View all of them and test them live at regex.to/patterns:
| Slug | Name | Category | Live Sandbox |
|------|------|----------|--------------|
| email | Email Address | Internet | Test Live ↗ |
| url | URL (HTTP/HTTPS) | Internet | Test Live ↗ |
| ipv4 | IPv4 Address | Network | Test Live ↗ |
| ipv6 | IPv6 Address | Network | Test Live ↗ |
| hex-color | Hex Color | Design | Test Live ↗ |
| semver | Semantic Version | Dev | Test Live ↗ |
| uuid | UUID | Dev | Test Live ↗ |
| credit-card | Credit Card Number | Finance | Test Live ↗ |
| iban | IBAN | Finance | Test Live ↗ |
| pl-nip | Polish NIP (Tax ID) | Finance | Test Live ↗ |
| pl-pesel | Polish PESEL | Identity | Test Live ↗ |
| us-zip | US ZIP Code | Address | Test Live ↗ |
| uk-postcode | UK Postcode | Address | Test Live ↗ |
Contributing
Adding new patterns is fully automated. Simply create a JSON file inside the patterns/ directory of the repository and open a Pull Request:
{
"slug": "my-custom-pattern",
"name": "My Custom Pattern",
"description": "Validates custom formats",
"category": "Web",
"pattern": "your[regex]+",
"flags": "i",
"examples": ["validexample"],
"counterExamples": ["invalidexample"],
"tags": ["custom"]
}The newly added pattern will be parsed automatically at build-time by both the NPM package and the regex.to dynamic website.
License
Released under the MIT License. Developed and maintained by the regex.to team.
