Skip to content
Regex

Common Patterns

Practical patterns for everyday validation.

By EZ4Code Team
patternvalidationemail

Code

Email:      ^[\w.+-]+@[\w-]+\.[\w.-]+$
URL:        ^https?://[\w.-]+(?:\.[a-z]{2,})+[\w./?&=-]*$
Phone:      ^\+?[\d\s()-]{7,}$
IPv4:       ^(\d{1,3}\.){3}\d{1,3}$
Date:       ^\d{4}-\d{2}-\d{2}$
Hex color:  ^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$
Integer:    ^-?\d+$
Slug:       ^[a-z0-9]+(?:-[a-z0-9]+)*$

Explanation

These patterns validate common inputs: emails, URLs, phone numbers, IPv4 addresses, dates, hex colors, integers, and URL slugs. They favor readability over strictness, so a real email check should also use DNS or SMTP verification. Always anchor patterns with ^ and $ and use case-insensitive flags where appropriate.

More Regex Snippets