title: preg_match regex to make http:// and https:// optional
body: <p>I want to validate URL in PHP but the function should accept the URL even if http:// or https:// not present in the input.</p>
  
  <p>Following URL's should be acceptable:</p>
  
  <pre><code>http://example.com
  http://www.example.com
  https://example.com
  https://www.example.com
  www.example.com
  example.com
  </code></pre>
  
  <p>It should not accept ftp protocol, IP address, Port, URL path, query, or fragment.</p>