Validating a url
Sometimes it's nice to be able validate field differently depending on the input itself.allows the validators object and validator options to be a function that should return the constraints/options: Validates the attributes object against the constraints.
There are no required external dependencies at all!
If you are running a PHP version older than 5.2 you are out of luck.
There is also a bug in PHP 5.2.13 and PHP 5.3.2 that will not allow URLs with dashes in them to validate.
If you are unsure of your PHP version you can run php -v from the command line if you have command line PHP installed, or create a PHP file with the following contents and navigate to it using your web browser: There is a lot of debate about whether using a regular expression is a good idea when doing URL validation.
If you are uncertain and looking for a guide then this may help: If you are using a version of PHP that is older than PHP 5.2: - Use the regular expression approach If you are using PHP 5.2.13 or PHP 5.3.2 and need URLs with dashes to validate: - Use the regular expression approach If you don't fall into one of the above categories: - Use the filter_var() approach Note: Some have complained that using the PHP filter_var() function is too permissive and allows URLs that should not validate.
Currently there are numerous solutions for validating URLs. the real issuse is that both methods dont check for "FILTER_FLAG_HOST_REQUIRED" which actually doesent work altough it should check ending... I have been trying to find a good solution for testing for URL's, I would not use the filter_var() for this kind of check. The only way i have found to check for them is either use regex or use the parse_url and check each section.