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?
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.

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
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
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

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
leakim971PluritechnicianCommented:
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

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
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
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
jQuery

From novice to tech pro — start learning today.