JSFiddle - React, Tailwind, and code Playground

HTML

<input type="text" id="domain">

JavaScript

$(document).ready(function(){
    $('#domain').blur(function(){
    var str = $.trim($(this).val());
    var pat = /^(?:https?:\/\/)?(?:www\.)?((?:(?!www\.|\.).)+\.[a-zA-Z0-9.]+)/gm;
    
    if (pat.test(str)){
        var match = str.match(pat);
        $(this).val(match);
    }
    else{
        $(this).val('Validation failed');
    }
});
});