title: JS Regex url validation
body: <p>I tried to validate url with or without http No matter what i did the function return false.
  I checked my regex string in this site:
  <a href="http://regexr.com/" rel="noreferrer">http://regexr.com/</a>
  And its seen as i expect.</p>
  
  <pre><code>    function isUrlValid(userInput) {
          var regexQuery = "/(http(s)?://.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&amp;//=]*)/";
          var url = new RegExp(regexQuery,"g");
          if (url.test(userInput)) {
              alert('Great, you entered an E-Mail-address');
              return true;
          }
          return false;
      }
  </code></pre>
  
  <p>I fix the problem by change the .test to .match and leave the regex as is.</p>