Production-ready regular expressions for email, URL, phone, password, IP address, and more — with explanations.
/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/
Matches: user@example.com, test.name+tag@sub.domain.co.uk
/^https?:\/\/[^\s/$.?#].[^\s]*$/i
For strict URL parsing, use new URL(str) and catch the error instead.
/^\+?1?[-.\s]?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$/
Matches: (555) 123-4567, 555.123.4567, +15551234567
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/
Requires: 8+ chars, one lowercase, one uppercase, one digit, one special character.
/^(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)$/
/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/
/^[a-z0-9]+(?:-[a-z0-9]+)*$/
Matches: hello-world, my-post-2025
/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i
Matches: #fff, #ff5733, #ff573380 (with alpha)
/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
/^(?:4\d{12}(?:\d{3})?|5[1-5]\d{14}|3[47]\d{13})$/
Detects Visa (4), Mastercard (51–55), Amex (34/37). Use Stripe in production.
Test all patterns with the Regex Tester.