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 ("usPhoneF ormat", 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 ("SocialNu mberFormat ", function (value, element) {
return this.optional(element) || /^\(\d{3}\) \d{3}\-\d{4}( x\d{1,6})?$/.test(value);
}, "Enter a valid social");
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
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
return this.optional(element) || /^\(\d{3}\) \d{3}\-\d{4}( x\d{1,6})?$/.test(value);
}, "Enter a valid social");
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.