JSFiddle - React, Tailwind, and code Playground
HTML
<input type="text" id="domain">
JavaScript
$(document).ready(function(){
$('#domain').change(function(){
var str = $.trim($(this).val());
var pat = /^(https?:\/\/)?(?:www\.)?([^\/]+)/;
if (pat.test(str)){
var match = str.match(pat);
console.log(match);
$(this).val(match[2]);
}
else{
$(this).val('Validation failed');
}
});
});