PHP validation flexible valid URI

Viewed 302

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

  1. should put http:// or https://
  2. validate host is true and flexible ex : localhost, example.com, www.example.com, sub.domain.com, 198.123.456.678
  3. should contain top-level domain (such as .com or .org and any else)

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

1 Answers
Related