ASP.Net button call javascript function

I have a javascript function that looks at input on a SSN and then corrects it for the proper dashes. I origincally used this in a traditional ASP page, and it worked fine. Now I want to use it in an ASP.Net page. The user enters a SSN and clicks a button to find the record. It returns the correct data for that number. The numbers are stored in the database with the XXX-XX-XXXX format. So when a user enters one without the dashes, this javascript cleans it up when the user clicks search. How can I get it to run in ASP.Net? I have the javascript in the page, but I'm not sure how to call it properly with the button. The On_Click event runs the search. Do I use it in the OnClientClick event? The button itself is simple:
<asp:Button ID="Find" runat="server" Text="Find User" onClick="Find_Click" onClientClick="form_Validation()"></asp:Button>

The javascript is here:

<script type="text/javascript">
  var reSSN = /^[0-9]{3}\-[0-9]{2}\-[0-9]{4}$/;
  var altSSN = /^\d{9}/;
  var altPattern = /(\d{3}) (\d{2}) )\d{4})/;

  function form_Validation(thisform) {

    with (thisform) {
        var SSN = SSN.value;

            if (SSN.length > 0) {
            if (altSSN.test(SSN)) {

                  SSN = SSN.replace(altPattern, "$1-$2-$3");
                  SSN.value = SSN;

            if (!reSSN.test(SSN)) {
                  alert("Social Security Number is not correct\nPlease use XXX-XX-XXXX\n");
                  return false;
      return true;
Who is Participating?
Brad HoweDevOps ManagerCommented:
Please take a read through the following article.

Essentially, JS and is not the same combination as old HTML/Classic ASP integration. You need to add the script to the form and add the attribute.

butSubmit.Attributes.Add("onClick", "return form_Validation();")

why u are not using validation control on the button for Social Security Number.
just use CompareValidator Control
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.