vendredi 27 février 2015

How to validate youtube url in client side in text box

I have to create a text box which only allows you tube url for videos.


To handle the validation in server side, I am using below code



$rx = '~
^(?:https?://)? # Optional protocol
(?:www\.)? # Optional subdomain
(?:youtube\.com|youtu\.be) # Mandatory domain name
/watch\?v=([^&]+) # URI with video id as capture group 1
~x';

$has_match = preg_match($rx, $url, $matches);


I was looking for the same solution for client side validation. I found about <input type="url"> here but it seems it is only for html5 browsers.


Is it possible to do client side validation with text box so that it will be compatible with all browser?


Thanks


Aucun commentaire:

Enregistrer un commentaire