Q:

Only do things if input-text is a domain like example.com

I would like to perform a whois-query if a user enters a valid domain.  This query should be done using AJAX. 
This script calls function checkDomain() always if the user types something into the form field:
js = jQuery.noConflict();
js(document).ready(function() {
    jQuery('#jform_domain').keyup(function() {
        checkDomain();
    });
});

function checkDomain() {
    var $this = jQuery(this);
    jQuery.ajax({
        url: '<? php echo JUri::root(); ? >/index.php',
        dataType: 'json',
        type: 'POST',
        data: {
            option: 'com_domaincheck',
            format: 'json',
            task: 'domain.checkDomain',
            domain: jQuery("#jform_domain").val(),
            '<? php echo JSession::getFormToken(); ? >': 1
        },
        success: function(response) {
            if (response.success) {
                console.log(response);
                jQuery("#test").html(response.message);
                // if (response.message == true) {} else {}
            } else {
                alert(response.message);
            }
        },
        error: function(data) {
            //console.log(data);
        }
    });
};

Now I would like to reduce unnecessary operations and start the script only, if the user entered a domain like:
example.com

It would be really, really, really cool, if the script would change inputs like www.example.com or http(s)://www.example.com to example.com aswell. 
I'm a beginner in JS and jQuery, so please do not blame me for my bad knowledge - I try to learn ;-)

A:

You need to use Regex for domain checking.  I have used a basic regex, you can modify this regex or use another to suit your needs.     
$(document).ready(function() {

    $regExDomain = /^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9]\.[a-zA-Z]{2,}$/;

    $('#domain_name').on('keyup', function(){
        if($regExDomain.test($(this).val() ) ){
           console.info("valid domain");
        }else{
           console.info("invalid domain");
           return false;
        }
        console.log("Valid domain");
        checkDomain();//domain is valid so call your ajax function
    });

});

