title: How to validate domain name using regex?
body: <p>This is my code for validating domain name.</p>
  
  <pre><code>function frmValidate() {
      var val = document.frmDomin;
      if (/^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9]\.[a-zA-Z]{2,}$/.test(val.name.value)) {
      }
      else {
          alert("Enter Valid Domain Name");
          val.name.focus();
          return false;
      }
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>&lt;form name="frmDomin" action="" method="post" onsubmit="return frmValidate();"&gt;
  Domain Name : &lt;input type="text" value="" id="name" name="name"  /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Now I entered <code>http://devp1.tech.in</code> and it alert the message. I want to enter sub domain also. How to change this? I should not get alert.</p>