I try this regex: ^(?:https?://)?(?:www.)?((?:(?!www.|.).)+.[a-zA-Z0-9.]+) in the validator here: regexplanet.com and the results are fine for the inputs provided but it fails in this fiddle:jsfiddle
<input type="text" id="domain">
$(document).ready(function(){
$('#domain').blur(function(){
var str = $.trim($(this).val());
var pat = /^(?:https?:\/\/)?(?:www\.)?((?:(?!www\.|\.).)+\.[a-zA-Z0-9.]+)/mg;
if (pat.test(str)){
var match = str.match(pat);
$(this).val(match);
}
else{
$(this).val('Validation failed');
}
});
What i try to do is to give: www.gmail.com, http://www.gmail.com, gmail.com/example etc and just get gmail.com