title: Regex validation rules
body: <p>I'm writing a database backup function as part of my school project.</p>
  
  <p>I need to write a regex rule so the database backup name can only contain legal characters.</p>
  
  <p>By 'legal' I mean a string that doesn't contain ANY symbols or spaces. Only letters from the alphabet and numbers.</p>
  
  <p>An example of a valid string would be <code>'31Jan2012'</code> or <code>'63927jkdfjsdbjk623'</code> or <code>'hello123backup'</code>.</p>
  
  <p>Here's my JS code so far:</p>
  
  <pre><code>    // Check if the input box contains the charactes a-z, A-Z ,or 0-9 with a regular expression.
  
      function checkIfContainsNumbersOrCharacters(elem, errorMessage){
          var regexRule = new RegExp("^[\w]+$");
          if(regexRule.test( $(elem).val() ) ){ 
              return true;
          }else{
              alert(errorMessage);
              return false;
          }
      }
  
  
  //call the function
  
  checkIfContainsNumbersOrCharacters("#backup-name", "Input can only contain the characters a-z or 0-9.");
  </code></pre>
  
  <p>I've never really used regular expressions before though, however after a quick bit of googling i found <a href="http://gskinner.com/RegExr/" rel="nofollow">this</a> tool, from which I wrote the following regex rule:</p>
  
  <pre><code>^[\w]+$
  </code></pre>
  
  <p>^ = start of string</p>
  
  <p>[/w] = a-z/A-Z/0-9</p>
  
  <p>'+' = characters after the string.</p>
  
  <p>When running my function, the whatever string I input seems to return false :( is my code wrong? or am I not using regex rules correctly?</p>