Link to home
Start Free TrialLog in
Avatar of maqskywalker
maqskywalker

asked on

regular expression formatting

Hi experts,

I saw this example that uses the jQuery Validation plugin and jQuery masked input plugin

http://jsfiddle.net/2hdTn/

In this example this custom validation method is used for United States phone number format which looks like this:

(123) 123-1234 x123456


jQuery.validator.addMethod("usPhoneFormat", function (value, element) {
    return this.optional(element) || /^\(\d{3}\) \d{3}\-\d{4}( x\d{1,6})?$/.test(value);
}, "Enter a valid phone number.");

this examples uses a mask like this for that us phone number

$(".phone").mask("?(999) 999-9999 x999999");

I'm tried to redo this example for a social security number format.

So my mask is like this $(".ssn").mask("###-##-####");

I'm having trouble writing the regular expression for a social security number format in my custom validation method.

Anyone know what  the syntax for my regular express in my method should be for a social format that looks like this:  123-45-6789  

So far I have this:

jQuery.validator.addMethod("SocialNumberFormat", function (value, element) {
    return this.optional(element) || /^\(\d{3}\) \d{3}\-\d{4}( x\d{1,6})?$/.test(value);
}, "Enter a valid social");
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial