title: Pattern validation with JavaScript
body: <p>I want a pattern with letters and numbers only.</p>
  
  <p>This is how I do it...</p>
  
  <p>JavaScript file:</p>
  
  <pre><code>var pattern_checked = checkPattern(); 
  
  function checkPattern(){
          var elem = document.getElementById("name");
  
          var pattern = elem.getAttribute("[a-zA-Z0-9_]");
          var re = new RegExp(pattern);
          if (re.test(elem.value)) {
              return true;
          } else {
              return false;
          }
      }
  </code></pre>
  
  <p>But in both the cases, I'm getting false.</p>
  
  <p>What is wrong in this code?</p>