How do I validate a asp.net field using javascript and pattern matching

I am trying to validate the presence and pattern of a field defined in an asp. net page.
The presence of the field works but when I enter the telephone number in the
field for pattern matching, it does not work. I get the error message.

Please advise,
Isaac

<div visible="true" id="divTelephoneNumber" runat="server">
                  <div class="col-xs-12 col-md-8 col-sm-10 col-lg-6 nill">
					<asp:Label ID="lblTelephoneNumber" runat="server" AssociatedControlID="txtTelephoneNumber" Text="Telephone number *" CssClass="control-label" />
                      <br />
					<asp:TextBox ID="txtTelephoneNumber" runat="server" CssClass="form-control" MaxLength="20" aria-label="Telephone number" ></asp:TextBox>
					<span class="required"></span>
                    <asp:CustomValidator id="rfVTN" runat="server" ControlToValidate="txtTelephoneNumber"  ValidateEmptyText="true" ErrorMessage="Telephone Number is a required field. nnn-nnn-nnnn " ClientValidationFunction="ValidateTelephone"/> 
                  </div>
                </div>            



 <script type="text/javascript">
       function ValidateTelephone(sender, args) {
           var compare = RegExp("/^(\()?\d{3}(\))?(-|\s)?\d{3}(-|\s)\d{4}$/");
           args.IsValid = compare.test(args.Value);
           return;
       }
</script>        

Open in new window

TechIsaacIT Contracting Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Robb HillSenior .Net Full Stack DeveloperCommented:
since there might be different phone formats you are doing...here is a link that shows you patterns and you should be able to choose the format that fits your validation.

http://regexlib.com/Search.aspx?k=phone&AspxAutoDetectCookieSupport=1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TechIsaacIT Contracting Author Commented:
Thanks, another issue is my javascript coding.

Thanks for the tip.
TechIsaacIT Contracting Author Commented:
Thanks again.

Isaac
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.