title: Regular expression validation - initialization error in Javascript
body: <p>I am trying to write a function in Javascript to validate email address. Here is the function.</p>
  
  <pre><code>function validateEmailAddress() {   
      var patternForEmail = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})$/;
      var regexPatternForEmail = new RegExp(patternForEmail, 'i');
  
      // Email address and the Confirm Email address values should match
      if ($('#txtEmail').val() != $('#txtConfirmEmail').val()) {
          $('#dvErrorMsg').html("Email addresses do not match.");
          $('#txtEmail').focus();
          return false;
      }
      else if (!regexPatternForEmail.test($('#txtEmail').val())) {
          $('#dvErrorMsg').html("Please enter a valid email address.");
          $('#txtEmail').focus();
          return false;
      }
      else
          return true;
  }
  </code></pre>
  
  <p>The problem here is I am getting an error, '<strong>Syntax error in regular expression</strong>' during RegExp object instantiation. </p>
  
  <p>I tried debuggin in IE 11 and that's where i found the error.
  Could someone please suggest me a solution for this.</p>
  
  <p><strong>Screen shot taken while debugging:</strong>
  <img src="https://i.stack.imgur.com/Yl1pD.jpg" alt="enter image description here"></p>