19 patterns
General Validation Regex Patterns
General-purpose validation patterns for the most common form validation needs. These cover required fields, character restrictions, input sanitization, and length enforcement - the building blocks of any form validation system.
Common Use Cases
All General Validation Patterns
Medium Password
6+ characters with at least 2 character types.
^(?:(?=.*[A-Z])(?=.*[a-z])|(?=.*[A-Za-z])(?=.*\d))[A-Za-z\d@$!%*?&]{6,}$Username
3-16 characters: letters, numbers, _ and -
^[a-zA-Z0-9_-]{3,16}$URL-friendly Slug
Slug for URLs (lowercase, hyphens).
^[a-z0-9]+(?:-[a-z0-9]+)*$Hexadecimal Color
3 or 6 character hex color with or without #.
^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$Hex Color with Alpha
Validates hex colors with alpha channel (4 or 8 digits).
^#?([A-Fa-f0-9]{8}|[A-Fa-f0-9]{4})$ISBN-10 or ISBN-13
Validates book ISBN numbers (10 or 13 digits).
^(?:ISBN(?:-1[03])?:? )?(?=[0-9X]{10}$|(?=(?:[0-9]+[- ]){3})[- 0-9X]{13}$|97[89][0-9]{10}$|(?=(?:[0-9]+[- ]){4})[- 0-9]{17}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?[0-9]+[- ]?[0-9]+[- ]?[0-9X]$UUID/GUID
Universally Unique Identifier format.
^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$RGB Color
Validates CSS RGB color format (0-255).
^rgb\(\s*(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})\s*,\s*(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})\s*,\s*(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})\s*\)$Base64 String
Validates Base64 encoded strings.
^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$ASCII Characters Only
Validates strings containing only ASCII characters.
^[\x00-\x7F]+$Basic Accented Text
Accented letters + digits + simple punctuation.
^[A-Za-zÀ-ÖØ-öø-ÿ0-9 ,.'"\-!?()°«»…–—]+$JSON String Detection
Basic detection of JSON strings (starts with { or [, ends with } or ]).
^[\{\[].*[\}\]]$Alphanumeric with Spaces
Allows only letters, numbers, and spaces — no special characters.
^[a-zA-Z0-9 ]+$No Leading or Trailing Spaces
Ensures the string has no leading or trailing whitespace.
^\S(.*\S)?$CSS HSL / HSLA Color
Validates HSL and HSLA CSS color notation including optional alpha and deg unit.
^hsla?\(\s*\d+(?:\.\d+)?(?:deg)?\s*,\s*\d+(?:\.\d+)?%\s*,\s*\d+(?:\.\d+)?%(?:\s*,\s*(?:0|1|0?\.\d+))?\s*\)$CSS RGB / RGBA Color
Validates RGB and RGBA CSS color notation. Allows optional alpha 0–1.
^rgba?\(\s*(?:25[0-5]|2[0-4]\d|1\d\d|\d{1,2})\s*,\s*(?:25[0-5]|2[0-4]\d|1\d\d|\d{1,2})\s*,\s*(?:25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(?:\s*,\s*(?:0|1|0?\.\d+))?\s*\)$HTTP Status Code
Matches a valid HTTP status code (100–599).
^[1-5]\d{2}$BCP 47 Language Tag
Validates BCP 47 language tags (e.g. en, fr-FR, zh-Hans-CN).
^[a-z]{2,3}(?:-[A-Z][a-z]{3})?(?:-[A-Z]{2})?(?:-[a-zA-Z0-9]+)*$License Key (XXXX-XXXX-XXXX-XXXX)
Matches a 4x4 grouped product license key (16 uppercase alphanumeric chars with dashes).
^[A-Z0-9]{4}(?:-[A-Z0-9]{4}){3}$Frequently Asked Questions
How do I validate that a field is not empty?
^\S+$ - matches any string with at least one non-whitespace character.
How do I allow only alphanumeric characters?
^[a-zA-Z0-9]+$ - no spaces, symbols, or special characters.
How do I enforce a minimum and maximum length?
Use quantifiers: ^.{8,32}$ for 8 to 32 characters of any kind.
Looking for patterns in other categories?
Browse all 300 patterns