I have a custom method for validating Youtube links, everything works great but it's still firing when the input is left blank.
How can I not have the custom method fire if the input is left blank, but still validate if something is inputted?
Method
jQuery(function() {
var youtubePattern = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=|\?v=)([^#\&\?]*).*/;
jQuery.validator.addMethod("youtubeVideo", function(value) {
return youtubePattern.test(value);
}, "Must be a valid Youtube video");
});
Validation
$( "#addPostsForm" ).validate({
rules: {
post_video: {
youtubeVideo: true
}
}