And to make sure the user gets a visual indication if the string isn’t a valid URL (according to the regex) there’s this CSS oneliner:
input[type=url]:invalid {color: red; border-color:red;}
The nice thing about this is that it is pretty backwards compatible;
And for browsers that do not support type=”url” nor patterns, there are multiple polyfills available that force older browsers to comply as well. But who cares about older browsers, right?