Reputation: 1114
i would to make a validation the URI is valid or not. I know this question has been ask before but i could find the flexible one, which it countain some rule
http://
or https://
localhost
, example.com
, www.example.com
, sub.domain.com
, 198.123.456.678
if the rule break, the response should tell which rule is false
so if the url :
https://example.com
, http://localhost
, it would return true
example.com
should be false, and the response is domain should be the domain must use either http or https
http://www.example
should be false, because the domain does not include top-level domain
https://198.123.456.678
and this one should be true too
those are what i expect
thank you
Upvotes: 4
Views: 333
Reputation: 455
Since you're using PHP, you can use [FILTER_VALIDATE_URL]
.
<?php
$uri = "https://www.stackoverflow.com" ;
if(filter_var($uri, FILTER_VALIDATE_URL)) {
echo("$uri is valid") ;
}
?>
See http://php.net/manual/en/filter.filters.validate.php for additional flags.
Upvotes: 1