# Common Regex Patterns

Practical patterns with the cases they cover.

| Purpose | Pattern |
|---|---|
| ISO date (format only) | `^\d{4}-\d{2}-\d{2}$` |
| Hex color | `^#?([a-fA-F0-9]{6}\|[a-fA-F0-9]{3})$` |
| URL slug | `^[a-z0-9]+(?:-[a-z0-9]+)*$` |
| US ZIP code | `^\d{5}(-\d{4})?$` |
| Simple IPv4 shape | `^(\d{1,3}\.){3}\d{1,3}$` |
| Trim whitespace | `^\s+\|\s+$` |
| Digits only | `^\d+$` |
| Username | `^[a-zA-Z0-9_]{3,16}$` |
| Simple email shape | `^[^\s@]+@[^\s@]+\.[^\s@]+$` |

These check **format**, not validity. An IPv4 pattern does not check ranges, and no regex fully validates email addresses. Confirm by sending a message.
