regex-pattern-validator
v1.0.0
Published
A collection of common and useful regex patterns (e.g., email validation, URL matching, etc.) that developers can easily import and use in their projects, saving time on writing and testing regex.
Downloads
1
Maintainers
Readme
Regex Pattern Library
A collection of common and useful regular expressions (regex patterns) that developers can easily import and use in their projects, saving time on writing and testing regex.
Features
- Email Validation
- URL Matching
- Phone Number Validation
- IP Address (IPv4) Validation
- Date (YYYY-MM-DD) Validation
- Hex Color Code Matching
- Username Validation
- Strong Password Validation
- HTML Tag Matching
- Floating Point Number Validation
- MAC Address Validation
- Base64 String Validation
- Social Security Number (SSN) Validation
- Credit Card Number Validation
- UUID (Universally Unique Identifier) Matching
- Non-ASCII Character Detection
- Only Letters (No Numbers or Special Characters) Matching
Installation
Install the package using npm:
npm install regex-pattern-library
Usage
You can import and use the regex patterns in your next projects:
Example
const {
emailPattern,
urlPattern,
strongPasswordPattern,
} = require("regex-pattern-library");
// Email Validation
console.log(emailPattern.test("[email protected]")); // true
// URL Validation
console.log(urlPattern.test("https://www.example.com")); // true
// Strong Password Validation
console.log(strongPasswordPattern.test("Password123")); // true
Available Patterns
| Pattern | Description | Example Usage |
| ----------------------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------- |
| emailPattern
| Validates email addresses | emailPattern.test('[email protected]')
|
| urlPattern
| Matches URLs (http, https, ftp) | urlPattern.test('https://example.com')
|
| phonePattern
| Validates phone numbers (E.164 format) | phonePattern.test('+1234567890')
|
| ipPattern
| Matches IPv4 addresses | ipPattern.test('192.168.0.1')
|
| datePattern
| Validates dates in YYYY-MM-DD format | datePattern.test('2024-09-08')
|
| hexColorPattern
| Matches hex color codes (#FFF, #FFFFFF) | hexColorPattern.test('#FF5733')
|
| usernamePattern
| Validates usernames (3-16 alphanumeric characters) | usernamePattern.test('user_123')
|
| strongPasswordPattern
| Validates strong passwords (min 8 chars, 1 uppercase, 1 lowercase, 1 number) | strongPasswordPattern.test('Password123')
|
| htmlTagPattern
| Matches HTML tags | htmlTagPattern.test('<div>')
|
| floatPattern
| Validates floating point numbers | floatPattern.test('3.14')
|
| macPattern
| Validates MAC addresses | macPattern.test('00:1A:2B:3C:4D:5E')
|
| base64Pattern
| Matches base64 encoded strings | base64Pattern.test('U29tZSBzdHJpbmc=')
|
| ssnPattern
| Validates US Social Security Numbers | ssnPattern.test('123-45-6789')
|
| creditCardPattern
| Matches basic credit card numbers | creditCardPattern.test('4111111111111111')
|
| uuidPattern
| Matches UUIDs | uuidPattern.test('123e4567-e89b-12d3-a456-426614174000')
|
| nonAsciiPattern
| Detects non-ASCII characters | nonAsciiPattern.test('测试')
|
| onlyLettersPattern
| Matches only letters (no numbers or special characters) | onlyLettersPattern.test('HelloWorld')
|
Contributing
Contributions are welcome! If you have a regex pattern you think should be included, feel free to open an issue or submit a pull request.