TL;DR — Quick Summary

Copy-paste regex patterns for validating emails, phone numbers, URLs, passwords, IPs, and dates. Includes comparison table with examples and language-specific syntax for JavaScript, Python, and C#.

Common Validation Patterns

Below is a reference table of commonly used regex patterns for field validation, originally sourced from the MSDN library and expanded with modern patterns.

FieldPatternExample MatchDescription
Email^[^\s@]+@[^\s@]+\.[^\s@]+$someone@example.comSimple email validation covering 99% of real addresses
URL^https?:\/\/[\w\-]+(\.[\w\-]+)+[\/\w\-\.~!$&'()*+,;=:@%]*$https://example.com/pathHTTP/HTTPS URLs with paths
Phone (US)^\(?(\d{3})\)?[-.\s]?(\d{3})[-.\s]?(\d{4})$(425) 555-0123US phone with optional parentheses and separators
Phone (International)^\+?[1-9]\d{1,14}$+521234567890E.164 format, 1-15 digits
ZIP Code (US)^\d{5}(-\d{4})?$12345 or 12345-67895-digit or ZIP+4 format
IPv4 Address^(\d{1,3}\.){3}\d{1,3}$192.168.1.1Basic IPv4 (add range check 0-255 in code)
Date (YYYY-MM-DD)^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$2026-02-28ISO 8601 date format
Password (strong)^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$P@ssw0rd!Min 8 chars, uppercase, lowercase, digit, special
Non-negative integer^\d+$0, 42, 986Zero or positive whole numbers
Currency^-?\d+(\.\d{2})?$1.00, -25.50Positive or negative with 2 decimal places
SSN^\d{3}-\d{2}-\d{4}$123-45-6789US Social Security Number format
Hex color^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$#FF5733, #F00CSS hex color codes
Slug^[a-z0-9]+(-[a-z0-9]+)*$my-blog-postURL-friendly slugs
Username^[a-zA-Z0-9_]{3,20}$john_doe423-20 alphanumeric + underscore

Language-Specific Syntax

LanguageCreate RegexTest MatchFind AllReplace
JavaScript/pattern/flagsregex.test(str)str.matchAll(/p/g)str.replace(/p/g, 'r')
Pythonre.compile(r'pattern')re.match(p, str)re.findall(p, str)re.sub(p, 'r', str)
C#new Regex(@"pattern")regex.IsMatch(str)regex.Matches(str)regex.Replace(str, "r")

Quick Reference: Metacharacters

CharacterMeaningExample
.Any character except newlinea.c → abc, a1c
\dAny digit (0-9)\d{3} → 123
\wWord character (a-z, 0-9, _)\w+ → hello_42
\sWhitespace (space, tab, newline)\s+ → matches spaces
^Start of string^Hello
$End of stringworld$
*Zero or more (greedy)ab*c → ac, abc, abbc
+One or more (greedy)ab+c → abc, abbc
?Zero or one (optional)colou?r → color, colour
{n,m}Between n and m times\d{2,4} → 12, 123, 1234
()Capture group(\d+)-(\d+)
(?=)Lookahead\d+(?=px) → 12 in “12px”