Validateur Regex d'Adresses URL
Validez des liens web, noms de domaine, paramètres d'URL et protocoles en direct. Idéal pour la sécurisation de vos API.
URL Regex Validation FAQ
What is the best regex pattern for validating URLs?
A standard, dependable URL regex for web applications is: /^(https?:\/\/)?((([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,})|localhost)(:\d+)?(\/[-a-z0-9%_.~+]*)*(\?[;&a-z0-9%_.~+=-]*)?(\#[-a-z0-9_]*)?$/i. It checks protocol, domain/subdomain, optional port, path, query parameters, and hash anchors.
Should a URL regex require http:// or https://?
It depends on user intent. In forms where users might type 'google.com' without the scheme, allow the protocol to be optional using (https?:\/\/)?. In security-sensitive redirects (OAuth callbacks), always strictly require https:\/\/.
How do I validate URLs in JavaScript without complex regex?
Modern browsers and Node.js support the new URL(string) constructor. However, combining a regex validator with the URL API is recommended because new URL('http://foo') parses successfully even for non-routable domains.