I'm looking to embed Youtube videos into a Meteor project, using urls submitted by users. I want to collect only the 11-character ID at the end of users' Youtube URLs. Someone seems to have figured something out for a browser's current url here. I just need a similar solution for a url provided in a form:
How to get anything following the domain in a url, using Javascript
Can anyone help this insert statement do that? Any help would be much appreciated.
Template.vidForm.events({
'submit #vid-form' : function(e, t) {
var title = t.find('#vid-title').value
, url = t.find('#vid-url').value;
if (isNotEmpty(title)
&& isNotEmpty(url))
{
vids.insert({user: Meteor.userId(), username: Meteor.user().username, date: new Date(), title: title, url: url}, function(err){
if (err)
Alerts.add('Submission error: ' + err.reason, 'warning');
else {
Alerts.add('Your video has been accepted.', 'success');
}
}
);
}
return false;
}
});