KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have the following regex to check to see if a URL is valid: preg_match('/^(http(s?):\/\/)?(www\.)?+[a-zA-Z0-9\.\-\_]+(\.[a-zA-Z]{2,3})+(\/[a-zA-Z0-9\_\-\s\.\/\?\%\#\&\=]*)?$/i', $url); I like to modify this part [a-zA-Z0-9\.\-\_]+(\.[a-zA-Z]{2,3}) (at least I hope it is this bold part) to be either an IP address or this highlighted part. At the moment, the regex is pretty good for me as it finds the bad URLs correctly - though I believe this will start failing to work correctly once the new domain policy from ICANN goes live (ie. Google may want to have the url http://search.google - instead of http://google.com for search) Anyhow, I'd like to add the ability to allow IP addresses to also be a valid URL, but I'm unsure how to factor that into the regex If anyone could lend a hand, then that would be great!
Tags (comma-separated)
Save Edits
Cancel