I've gone through all possible ways for having the regular expression for the url validation, but I didn't get any.. what I need is the url can be like
google.com
http://google.com
https://google.com
http://www.google.com
https://www.google.com
but it should not allow if it is just google
finally the thing is the .extensions
are mandatory
I've tried this /^[a-z0-9-]+(.[a-z0-9-]*)(.[a-z0-9-]*)$/
can anyone help me in this case..
You can directly validate url using filter_var
and FILTER_VALIDATE_URL
if (filter_var($url, FILTER_VALIDATE_URL) !== false)
Edit
With Regex
$subject = "http://www.google.com";
$pattern = "/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i";
preg_match($pattern, $subject, $matches);
print_r($matches);
Array ( [0] => http://www.google.com )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With