URL Regex: Validate Website URLs
Use these URL regex patterns to validate URLs with or without http/https, plus copy-ready JavaScript, Python, and HTML examples.
Use these URL regex patterns to validate website URLs with or without http or https. Below you will find the exact regexes, copy-ready examples for JavaScript, Python, and HTML forms, plus common URL validation mistakes.
URL regex
Use one regex for URLs that must start with http:// or https://, and a different one if protocol is optional.
Primary pattern for HTTP/HTTPS URLs:
^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,63}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$
Pattern for URLs without protocol:
^[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,63}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$What the HTTP/HTTPS pattern matches:
- https://uibakery.io
- http://example.com/docs
- https://www.example.org/pricing?plan=pro
What it does not match:
- ftp://example.com
- https:/example.com
- /docs/page
- just-text
Quick note: If you need to match local URLs, IP addresses, or every RFC-compliant edge case, use a more specialized validator instead of one generic regex.
URL regex that starts with HTTP or HTTPS
HTTP and HTTPS URLs that start with protocol can be validated using the following regular expression
True
False
Enter a text in the input above to see the result
Example code in Javascript:
URL regex that doesn’t start with HTTP or HTTPS
The regular expression to validate URL without protocol is very similar:
True
False
Enter a text in the input above to see the result
Example code in Javascript:
Common mistakes
1. Using one regex for every possible URL
There is no single short regex that perfectly validates all valid URLs. For example, you may need separate logic for:
- http and https URLs
- domains without protocol
- localhost
- IP addresses
- internal relative paths
This page covers common website URLs, not every edge case.
2. Forgetting to define whether protocol is required
These two cases should not use the same validation rule:
- https://uibakery.io
- uibakery.io
If protocol is required, use the HTTP/HTTPS regex. If protocol is optional, use the domain-based regex.
3. Using URL regex for relative paths
Values like these are not full URLs:
- /pricing
- /docs/getting-started
- ../assets/file.pdf
If your form accepts internal paths, use a separate path validation pattern.
4. Expecting regex alone to verify the page exists
Regex only checks format. It does not confirm that:
- the domain exists
- the page is live
- SSL is valid
- the target returns 200 OK
If you need that, you need an additional request or backend validation step.
True
False
Enter a text in the input above to see the result
Notes on URL validation
The above-mentioned regular expressions only cover the most commonly used types of URLs with domain names. If you have some more complex cases you might need a different solution.
