Create a social security validation for jquery validator plugin

I am using this plugin:

And I would like to create a custom rule that validates for US social security numbers. (###-##-####), I know it can be done, I have done stuff like this in the past but I am on deadline and I don't have time to figure it out.

If I could just use a regex as a validation rule that would be cool since I am pretty good with that.

Michael SoleDirector of SupportAsked:
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.

\Since you are already using the plugin, and already good at regex, this should be a snap for you!

Yours could be identical  to the example for "To validate Phone Number" - except for the error message, of course.
Michael SoleDirector of SupportAuthor Commented:
I want to use the plugin since the form has a lot of fields and they are all already being used with this plugin. I'd rather not mix plugins
Is the tutorial I linked for a different plugin with the same name?
Michael SoleDirector of SupportAuthor Commented:
Upon review it is the same plugin but my question was how to write this specific validation rule, not provide me with a link. I don't mean to be snarky but I could of RTFW'ed without asking you to tell me to do it.
It took you longer to type your comment than to get the code and make the necessary adjustments from "phone" to "SSN".  The only "coding" on your part is updating the regex that you said you are good at, so yes, I linked to the source rather than adjusting it for you - especially since the edits to make it say "SSN" instead of phone are the same edits you will need to make for it to use your field ID and your error message...

    $.validator.addMethod("NumbersOnly", function(value, element) {
        return this.optional(element) || /^[0-9\-]+$/i.test(value);
    }, "SSN must contain only numbers and -.");

Open in new window

and now you can validate specifying class=”required NumbersOnly”. This will allow only numbers 0-9, and a hyphen.
  <td><input name="SSN" type="text" id="SSN" class="required NumbersOnly"></td>

Open in new window

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

From novice to tech pro — start learning today.