validate http:// or https:// using regex









You can validate http:// or https:// using the methods below:

$link = "http://site.com";  or $link = "https://site.com";
Example: My values would be either of the two, with or without "s".

Method 1:
echo preg_match("^(http(s?))://^", $link);  I prefer this method

Method 2:
echo preg_match("^(http|https)://^", $link); 
This entry was posted in regex and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>