Best Method to Validate URL
Permalink 1 user found helpful
I am working on a block that requires a URL to be entered. I have tried searching, but haven't found anything that works. The block form has this:
In the block controller, I have tried these:
and
Neither of those work.
What is the best way to validate URLs?
<?php echo $form->url('iframeurl', $iframeurl?$iframeurl:"");?>
In the block controller, I have tried these:
$validurl = '%^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@|\d{1,3}(?:\.\d{1,3}){3}|(?:(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)(?:\.(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)*(?:\.[a-z\x{00a1}-\x{ffff}]{2,6}))(?::\d+)?(?:[^\s]*)?$%iu'; if(!preg_match($validurl,($args[$iframeurl]))) { $e->add(t("Iframe URL is invalid.")); }
and
if(!filter_var(($args[$iframeurl]), FILTER_VALIDATE_URL) === false) { $e->add(t("IFrame URL is invalid.")); }
Neither of those work.
What is the best way to validate URLs?
http://www.w3schools.com/php/php_form_url_email.asp...
Hopefully this should work for you - I use this in most of my web applications