views:

167

answers:

1

I recently found out about oEmbed which is "a fomat for allowing an embedded representation of a URL" basically you enter the url of a youtube video that you like and oEmbed will return the embedded code of the video in this page.

I want to give my users the option to either enter a url or embed code in a textbox. If is embed code it should leave the text as it is, but if it is a url it should get the embed code from oEmbed.

My problem is the following: how do I identify if the user paste an embed code or a url?


$(document).ready(function() {
    $('#embedCode').bind('paste', function(e) { 
     // time out until the value has been pased to the textbox
        setTimeout(function() {
            var code = $('#embedCode').val();
         var tagCount = 0;

         // Identify embedded code here

         if(tagCount == 0) {
       alert('LINK');
         }
         else {
             alert('EMBED');
         }
        }, 100);    

    });

});

I was thinking to add a method to count the the number of valid tags such as object and param but have had no luck trying to do this.

Any ideas?

Thank you

+1  A: 
//Using a youtube video page as an example:

if( $('#embedForm input').val().toLowerCase().indexOf('<object') > -1 )
{
    //input value has an OBJECT tag
}
micahwittman
This worked ok, I just used the id of the textbox instead of $('#embedForm input')Thank you
Onema