title: Regular Expression Pattern matching issue
body: <p>Not a lot of experience in RegEx stuff.</p>
  
  <p>I have the following in java script which works perfectly fine.</p>
  
  <p>The following pattern is used allow only alpha numeric</p>
  
  <pre><code>var valid = /^[A-Za-z0-9]+$/.test("a"); // returns true
  var valid = /^[A-Za-z0-9]+$/.test("@"); // returns false
  </code></pre>
  
  <p>I am using the pattern part "^[A-Za-z0-9]" in some other places of the code and was asked to use the part "^[A-Za-z0-9]" in a variable and use it so that it is not repetitive. The following is a modification to the above:</p>
  
  <pre><code>var regExPart= "^[A-Za-z0-9]";
  var regExString = ("/" + regExPart+ "+$/".replace(/\"/g, "")); // replacing the quotes
  var regExp = new RegExp(regExString); // results in /^[A-Za-z0-9]+$/
  var valid = regExp.test(charValue); // charValue could be any keyvalue "a" or "@"
  
  //the above returns false for "a" 
  //the above returns false for "@"
  </code></pre>
  
  <p>I am writing this in a keypress event to allow only alpha numeric</p>
  
  <pre><code>keypressValidation: function (e) {
  var charCode = (e.which) ? e.which: event.keyCode;
  var charValue = String.fromCharCode(charCode);
  var valid = return /^[A-Za-z0-9]+$/.test(charValue);
  if (!valid) 
  {
      //prevent default (don't allow/ enter the value)
  }
  </code></pre>
  
  <p>Not sure why. What am I missing in this. Need to <strong>return true for "a" and false for "@" for both the approaches.</strong> Any help/ suggestion would be of great help. Thank in advance.</p>