JSFiddle - React, Tailwind, and code Playground
HTML
<a target="_blank" href="www.google.com">Google</a>
<br>
<a target="_blank" href="//google.com">Google</a>
<br>
<a target="_blank" href="http://www.google.com">Google</a>
<br>
<a target="_blank" href="https://www.google.com">Google</a>
<br>
<a target="_blank" href="//www.google.com">Google</a>
<br>
<a target="_blank" href="https//www.google.com">Google</a>
<br>
<a target="_blank" href="http//www.google.com">Google</a>
CSS
a {
display:block;
margin-bottom:20px;
}
JavaScript
function filterValidUrl(item) {
var regularExpression = /^(https?|\/\/)/;
return regularExpression.test($(item).attr('href'));
}
$('a').filter(function () {
return /^https?\/\//.test($(this).attr('href')); }).attr('href', function() {
return $(this).attr('href').replace('https//', 'https://').replace('http//','http://');
})
$('a').filter(function () { return !filterValidUrl(this); }).attr('href', function() {
return "//" + $(this).attr('href');
})