Blog
TutorialJune 1, 2026

Regex for URL Validation

URL validation regex helps catch malformed links in forms and APIs. The right pattern depends on whether you need strict RFC compliance or practical validation.

HTTP/HTTPS Pattern

Basic: ^https?://[\w.-]+(?:\.[\w.-]+)+[\w._~:/?#[\]@!$&'()*+,;=%-]*$. This matches common web URLs with optional paths and query strings.

When to Use URL Parser Instead

For complex validation (port numbers, IPv6, fragment identifiers), use the URL constructor: new URL(input). Regex is fine for quick form validation; URL API is better for parsing and normalization.

Pair URL validation with WaiHub's URL Encoder for encoding and Query ↔ JSON conversion.