jQuery validator addMethod phoneRU function phone_number element phone

1
2
3
4
5
6
7
8
9
jQuery.validator.addMethod("phoneRU", function(phone_number, element) {
phone_number = phone_number.replace(/\s+/g, "");
phone_number = phone_number.replace('(', "");
phone_number = phone_number.replace(')', "");
phone_number = phone_number.replace(/-/g, "");
return this.optional(element) || phone_number.length > 9 &&
phone_number.match(/(\+7|8)9([0-9]{2})[1-9]([0-9]{6})/);
}, "Please specify a valid phone number");