title: JavaScript - How to check for URL with specific domain name?
body: <p>How would I use JavaScript to look for a specific domain name and then return true if its the one I am looking for, or false if it is not the URL that I am looking for. In my example a user types a URL in an input box, JavaScript checks if it is a specific domain such as <a href="https://example.com" rel="nofollow noreferrer">https://example.com</a> and then redirects the user to that page. If they type another URL without the <a href="https://example.com" rel="nofollow noreferrer">https://example.com</a>, JavaScript will return false and show an error message. If a user types the URL <a href="https://example.com/join/1234" rel="nofollow noreferrer">https://example.com/join/1234</a> I just wish to check the main domain. The code I have so far is below. I have tried using regex butI dont know how I can make it only check the domain name -> <a href="https://example.com" rel="nofollow noreferrer">https://example.com</a> . </p>
  
  <pre><code> &lt;div class="col-md-12 col-lg-5"&gt;&lt;button class="btn btn-primary btn-lg" id = "start-call" data-aos="zoom-in" data-aos-duration="900" data-aos-delay="2000" type="button" style="margin: 160px;width: 135px;" onclick = "goToCall()" &gt;Start Call&lt;/button&gt;&lt;/div&gt;
  
  
   function isDomainURL(str){
    regexp =  /^(?:(?:https?|ftp):\/\/)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/\S*)?$/;
      if (regexp.test(str)){
  
      return true;
  
      }else{
  
      return false:
  
      }
  
   }
  
   if (isDomainURL(document.getElementById('input-01').value) == true)
      {
          window.location = document.getElementById('input-01').value;
      }
      else
      {
          swal({
              title: "Invalid URL",
              text: "Thats was an invalid DropCall URL.",
              icon: "error",
          });
      }
  </code></pre>