I am using the regex here jQuery Youtube URL Validation with regex
^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$
It works fine here https://regex101.com/#javascript
But my code is not working- I am using jquery.validate.min.js and additional-methods.js
My code below works fine with other Regexes but with this one is not working, it always says invalid:
var yt = new RegExp("^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$");
$("#submit-form").validate({
// Specify the validation rules
rules: {
yturl: {
required: true,
minlength: 3,
pattern: yt
}
},
messages: {
yturl: {
pattern: "Wrong url"
}
}
Thanks