Validate SSN in jQuery

Hi Experts,
I am developing .ASPX Web Page in VS2003.  I need to validate SSN in jQuerey.  Any idea?  Thanks in advance.
RadhaKrishnaKiJayaAsked:
Who is Participating?
 
leakim971Connect With a Mentor PluritechnicianCommented:
You miss to include the jquery.maskedinput.js


<HTML>
      <HEAD>
      <title>Demo2</title>

    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js" type="text/javascript"></script>
    <script src="http://digitalbush.com/files/jquery/maskedinput/rc3/jquery.maskedinput.js" type="text/javascript"></script>
 
      <script language="javascript"> 
            $.validator.setDefaults({
                  submitHandler: function() { alert("submitted!"); }
            });

            $().ready(function() {
                  $("#ssn").mask("999-99-9999");
                  $("#myForm").validate({ 
                    rules: { 
                         name: "required", 
                           ssn: "required" 
                        }, 
                        messages: { 
                              name: "Please enter your name!", 
                           ssn: "Please enter your ssn!" 
                      } 
                  });
            });
      </script>

      <form id="myForm">
            <fieldset>
                  <legend>
                        My Sample Form</legend>
                  <label><strong>Name:</strong></label><br>
                  <input name="name" id="name">
                  <br>
                  <label><strong>SSN:</strong></label><br>
                  <input name="ssn" id="ssn">
                  <br>
                  <input class="submit" type="submit" value="submit">
            </fieldset>
      </form>

</body>
</HTML>

Open in new window

0
 
VenabiliCommented:
I am usually using http://digitalbush.com/projects/masked-input-plugin/ when I need something like this...
And then something similar to http://stackoverflow.com/questions/982027/jquery-validate-and-grouping-similar-form-items for the validations...

Alternatively, just use a regex: ^\d{3}-\d{2}-\d{4}$
0
 
VenabiliCommented:
And of course - why do you need it in jQuery? That's client side validation so why not make in Javascript directly? http://javascript.internet.com/forms/val-ssn.html for example
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
RadhaKrishnaKiJayaAuthor Commented:
Hi Venabilli,
I need it in jQuery as all other validations are in jQuere.  I tried your 1st suggestion.  It did not work for me.  In fact nothing happened when hit submit button.  Probably it is not able to find the jQuery plugin libraries required for validations.  In fact I need a simple example which should work.  Thank you very much for your help though.
0
 
VenabiliCommented:
How do you do your validations? Do you use http://bassistance.de/jquery-plugins/jquery-plugin-validation/ ?

If you do,  http://stackoverflow.com/questions/280759/jquery-validate-how-to-add-a-rule-for-regular-expression-validation has quite a good discussion on how to implement a regex one and I  gave you a regex to use above.

If not - can you show how you do your validations?
0
 
RadhaKrishnaKiJayaAuthor Commented:
At this point I don't need to use the validation any more.  I will update you when I need it again.
0
 
VenabiliCommented:
So what did you end up using?

You cannot just dismiss a question because you do not need it -- especially after leaving it hanging for 2 months
0
 
RadhaKrishnaKiJayaAuthor Commented:
Venabili:
I am not dismissing it, but did not find any specific reply so far, and at the same time my priority changed little bit.  Now I am back.  I looked at the link http://stackoverflow.com/questions/280759/jquery-validate-how-to-add-a-rule-for-regular-expression-validation.  It talks about some custom rules, which is very difficult to follow.  It doesn't talk anything about SSN validation of in jQuery.  My question is very simple.  Is it possible for you to provide me a simply resolution?

Thanks.
0
 
leakim971PluritechnicianCommented:
0
 
RadhaKrishnaKiJayaAuthor Commented:
Hi leakim971,
Yes, It is something like this.  But I tested the code, which is not working.  Looks like there is problem in the mask.  When I comment it out, it works, but doesn't validate the SSN in its format.  Here is the code below, please take a look if you can.  Thanks.

<HTML>
      <HEAD>
      <title>Demo2</title>

    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js" type="text/javascript"></script>
 
      <script language="javascript">
            $.validator.setDefaults({
                  submitHandler: function() { alert("submitted!"); }
            });

            $().ready(function() {
                  $("#ssn").mask("999-99-9999");
                  $("#myForm").validate({
                    rules: {
                         name: "required",
                           ssn: "required"
                        },
                        messages: {
                              name: "Please enter your name!",
                           ssn: "Please enter your ssn!"
                      }
                  });
            });
      </script>

      <form id="myForm">
            <fieldset>
                  <legend>
                        My Sample Form</legend>
                  <label><strong>Name:</strong></label><br>
                  <input name="name" id="name">
                  <br>
                  <label><strong>SSN:</strong></label><br>
                  <input name="ssn" id="ssn">
                  <br>
                  <input class="submit" type="submit" value="submit">
            </fieldset>
      </form>

</body>
</HTML>
0
 
RadhaKrishnaKiJayaAuthor Commented:
Thank you leakim971 for your help.  This works great.  Many many thanks to you.  I think I can close this case now.
0
All Courses

From novice to tech pro — start learning today.