Pattern:^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
What it does:
Ensures the email consists of:
Pattern:^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$
What it does:
Checks if the input is a valid HTTP or HTTPS URL, including:
http://
or https://
)Pattern:^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$
What it does:
Enforces a strong password with:
@
, $
, !
, %
, *
, ?
, &
)Pattern:^(19|20)\d\d-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$
What it does:
Validates dates in ISO format, ensuring:
Pattern:^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$
What it does:
Matches 3-digit or 6-digit hex color codes, with an optional #
prefix.
Pattern:^(\+1\s?)?(\([2-9][0-8][0-9]\)|[2-9][0-8][0-9])[-.\s]?([2-9][0-9]{2})[-.\s]?([0-9]{4})$
What it does:
Validates US phone numbers with:
+1
)[2-9][0-8][0-9]
)-
, .
, or spacesPattern:\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b
What it does:
Matches a valid IPv4 address, ensuring each octet is between 0 and 255.
Pattern:^(?!000|666)[0-8]\d{2}-(?!00)\d{2}-(?!0000)\d{4}$
What it does:
Validates US SSNs while excluding:
000
, 666
in the first segment00
in the middle segment0000
in the last segmentBookmark this guide to quickly reference these essential regex validations in your projects. With these patterns, you can ensure data integrity and improve user input validation effortlessly.
Happy coding! 💻✨