Jump to content

[SOLVED] Perfect URL validation


detest

Recommended Posts

I've come across some URL validation regexes and even a PHP function, but they all contain flaws!

 

ex. the PHP function: filter_var($url, FILTER_VALIDATE_URL)

This says the input "http://www.example.com/http://www.example.com/" is valid!

 

ex. the regex: return preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url);

This also says the input "http://www.example.com/http://www.example.com/" is valid!

 

 

So I would like perfect URL validation.

Also, I would like to avoid "http://", so the inputted url "www.example.com" would be valid.

 

Thanks in advance.  :)

Link to comment
https://forums.phpfreaks.com/topic/130927-solved-perfect-url-validation/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.