title: Why isn't this working asp.net and javascript to validate pattern -
body: <p>I am trying to validate a field for not empty(spaces) and pattern matching
  but the no spaces work but pattern matching causes error.</p>
  
  <p>I've tried a few variations but it's not working. The field I'm trying to
  validate is undefined.</p>
  
  <pre><code>&lt;div visible="true" id="divTelephoneNumber" runat="server"&gt;
      &lt;div class="col-xs-12 col-md-8 col-sm-10 col-lg-6 nill"&gt;
          &lt;asp:Label ID="lblTelephoneNumber" runat="server" AssociatedControlID="txtTelephoneNumber" Text="Telephone number *" CssClass="control-label" /&gt;
          &lt;br /&gt;
          &lt;asp:TextBox ID="txtTelephoneNumber" runat="server" CssClass="form-control" MaxLength="20" aria-label="Telephone number" &gt;&lt;/asp:TextBox&gt;
          &lt;span class="required"&gt;&lt;/span&gt;
          &lt;asp:CustomValidator id="rfVTN" runat="server" ControlToValidate="txtTelephoneNumber"  ValidateEmptyText="true" ErrorMessage="Telephone Number is a required field. nnn-nnn-nnnn " ClientValidationFunction="ValidateTelephone"/&gt; 
      &lt;/div&gt;
  &lt;/div&gt; 
  
  &lt;script type="text/javascript"&gt;
      function ValidateTelephone(sender, args) {
          var rxP = RegExp("/^(\()?\d{3}(\))?(-|\s)?\d{3}(-|\s)\d{4}$/");
          if (rxP.IsMatch(txtTelephoneNumber.Text))
          {
              args.IsValid = true;
          }
          args.IsValid = false;
          return;
      }
  &lt;/script&gt;  
  </code></pre>