开发者

Youtube url tester with hyphens

this is how i normally check for youtube url validity using javascript. It works great but fails for urls with "-" before the video id eg htt开发者_高级运维p://www.youtube.com/watch?v=-pIaQpwYEjY

Any remedy available as I'm not well versed with regex

var matches = $('#as_url').val().match(/^http:\/\/(?:www\.)?youtube.com\/watch\?(?=.*v=\w+)(?:\S+)?$/);
if (matches) {
} else {
    error +="\nInvalid Youtube Url";
}


Change \w+ to [\w-]+, since the \w character class only matches [A-Za-z0-9_].

Regular-Expressions.info has a good explanation of what character classes are, as well as the lookahead feature of regexes, both of which your regex uses.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜