Validate URLs instantly using our URL Regex JavaScript Validator. Whether you’re working with user-submitted forms, scraping data, or handling API calls, this tool helps ensure every link is correctly formatted. It supports http and https, subdomains, query parameters, and more. Pair it with tools like the JavaScript Regex Tester to test patterns live, or use the Token Generator and Base64 Encoder to safely handle encoded URLs and access tokens.
[A-Z]
: uppercase letters[a-z]
: lowercase letters[0-9]
: digits\.
: a literal dot+
: one or more of the preceding*
: zero or more of the preceding?
: optional (zero or one)^
: start of string$
: end of string
Test your APIs today!
Write in plain English — Qodex turns it into secure, ready-to-run tests.
Regular Expression - Documentation
What is URL Regex in JavaScript?
In JavaScript, a URL regex (regular expression) is used to check whether a given string follows the structure of a valid web address. This can include HTTP or HTTPS links, domain names, and optional paths or query parameters. Regex helps developers filter out invalid or malformed links in user input, APIs, and forms.
URL regex patterns are useful for:
Validating links in forms and user input
Extracting URLs from text or logs
Cleaning and processing data in web scraping or automation scripts
Preventing invalid links from being submitted to servers
Common URL Regex Pattern (JavaScript)
A commonly used regex for basic URL validation is:
This pattern checks:
Optional http or https
A valid domain name
An optional path and query string
How to Validate URLs in JavaScript Using Regex
Here’s how you can use regex to validate a URL in JavaScript:
Examples of Valid and Invalid URLs
Input | Valid? |
---|---|
https://example.com | Yes |
http://sub.domain.co.uk | Yes |
ftp://invalid.protocol.com | No |
example..com | No |
Pro Tips for Using URL Regex in JavaScript
Use non-capturing groups when you don’t need to extract sub-matches. It improves performance.
Combine this with the JavaScript Regex Tester to test complex patterns interactively.
Avoid overly strict patterns—some valid URLs might be blocked unintentionally.
Normalize input before validation (e.g., trimming whitespaces).
Pair it with tools like the Token Generator to validate URLs containing access tokens or the Base64 Encoder for secure URL components.
Regex Metacharacters Used
^
: Anchors the match at the start of the string$
: Anchors the match at the end of the string?
: Marks the preceding token as optional()
: Capturing group(?:)
: Non-capturing group[]
: Character set.
: Matches any character except newline+
: Matches one or more occurrences*
: Matches zero or more occurrences\/
: Escaped slash (for path components)
Combine with These Tools
JavaScript Regex Tester – Live test any pattern.
Token Generator – Validate tokenized URL parameters.
Base64 Encoder – Encode data inside URLs.
UUID Regex JavaScript Validator – Match UUIDs used in RESTful URLs.
Email Regex JavaScript Validator – Validate email addresses often linked in forms.
Phone Number Regex JavaScript Validator – For contact forms that include phone and URL fields.