I am using a regex to try and validate URL's. The regex I have works very well but the only issue is that it validates URL's even if there is no http:// in the front. I want it to only validate if the URL has http:// in the front (even if it doesn't contain a www right after)
This is the regex I'm using:
((https?)\:\/\/)?([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)?([a-z0-9-.]*)\.([a-z]{2,3})(\:[0-9]{2,5})?(\/([a-z0-9+\$_-]\.?)+)*\/?(\?[a-z+&\$_.-][a-z0-9;:@&%=+\/\$_.-]*)?(#[a-z_.-][a-z0-9+\$_.-]*)?
filter_var('http://example.com', FILTER_VALIDATE_URL)but it validates urls such ashttp://example.candhttp://example.comxxwhich should not validate. What native PHP function would you suggest?