I am adding in a custom method for the jQuery Validation plugin to check for a valid phone number. However, I want this field to be optional, and not required. For some reason, when I add the following code in, it is making fields with the class "phone" required too. Any ideas what I'm doing wrong?
$.validator.addMethod("phone", function(ph, element) {
var stripped = ph.replace(/[\s()+-]|ext\.?/gi, "");
// 10 is the minimum number of numbers required
return ((/\d{10,}/i).test(stripped));
});
$('#custom').validate({
errorPlacement: function(error, element) {
return true;
}
});
<input type="text" class="phone" name="phone_1" id="phone_1">