Skip to content

Regex Examples

Email Address

/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/

Phone Number

Matching a phone number (US format)

/^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}$/

URL

/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/

Date

Matching a date (YYYY-MM-DD format)

/^\d{4}-\d{2}-\d{2}$/

Hexadecimal Color Code

/^#?([a-f0-9]{6}|[a-f0-9]{3})$/

Strong Password

Matching a strong password (at least 8 characters, at least one uppercase letter, one lowercase letter, one number and one special character).

/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/

MAC Address

/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/

IP Address

Matching an IP address (IPv4)

/^(?:(?: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]?)$/