'Url is in wrong format', self::INVALID_ID => 'Wrong video id', ]; /** * Pattern for youtube url validation * @link http://stackoverflow.com/questions/2964678/jquery-youtube-url-validation-with-regex * @var string */ protected $_pattern = '/^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/'; /** * Url pattern used to validate videoId * @var string */ protected $_dataUrlPattern = 'http://gdata.youtube.com/feeds/api/videos/%s'; public function __construct(array $options = []) { if (isset($options['messages'])) { $this->setMessages($options['messages']); } } protected function _validateVideoId($videoId) { $url = sprintf($this->_dataUrlPattern, $videoId); if (ini_get('allow_url_fopen')) { if (($handle = fopen($url, 'rb')) && ($data = fread($handle, 256)) && ('_setValue($value); if (false == preg_match($this->_pattern, $value, $match)) { $this->_error(self::INVALID); return false; } if (false == $this->_validateVideoId($match[1])) { $this->_error(self::INVALID_ID); return false; } return true; } }