I have You-tube embed code field in my form. How I validate that?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Do you want to validate on the user end or on the server end? I once had a form that required this. My solution was to use javascript to insert the embed code directly into the page and therefore allow a user to preview their copy/paste job before finally submitting the form. Facebook pretty much does the same thing when posting a Youtube link.
On the server-side, there are two things that I think could help you: the Youtube API, and the fact that every video on Youtube has a “v” parameter. The API allows for searching by this video id. (Details here: http://code.google.com/apis/youtube/2.0/developers_guide_protocol_video_entries.html)
You would then determine from the API response whether or not that video exists. The only other tricky part might be finding the “v” parameter in the embed code, because I believe the embed code changes from time to time. For instance
is part of the embed code. And this is the link to that same video on YouTube:
Furthermore if you just pull out the URL from the embed code and paste it in your browser, it actually works as well.
So, in summary, get acquainted with the Youtube API in your language of choice, figure out how to parse the “v” parameter from embed code, and use them together.