title: How to validate youtube url in client side in text box
body: <p>I have to create a text box which only allows you tube url for videos. </p>
  
  <p>To handle the validation in server side, I am using <a href="https://stackoverflow.com/a/13476188/1877909">below code</a> </p>
  
  <pre><code>$rx = '~
      ^(?:https?://)?              # Optional protocol
       (?:www\.)?                  # Optional subdomain
       (?:youtube\.com|youtu\.be)  # Mandatory domain name
       /watch\?v=([^&amp;]+)           # URI with video id as capture group 1
       ~x';
  
  $has_match = preg_match($rx, $url, $matches);
  </code></pre>
  
  <p>I was looking for the same solution for client side validation. I found about  <code>&lt;input type="url"&gt;</code> <a href="https://stackoverflow.com/a/13821385/1877909">here</a> but it seems it is only for html5 browsers.</p>
  
  <p>Is it possible to do client side validation with text box so that it will be compatible with all browser?</p>
  
  <p>Thanks </p>