20 lines
732 B
Python
20 lines
732 B
Python
from django.core.validators import RegexValidator
|
|
|
|
# Supported formats:
|
|
# - http://(www.)youtube.com/watch?v=Dhjiu89G3
|
|
# - http://(www.)youtube.com/watch/Dhjiu89G3
|
|
# - http://youtu.be/Dhjiu89G3
|
|
|
|
class YoutubeURLValidator(RegexValidator):
|
|
regex = r'https?:\/\/(((www.)?youtube.com\/((watch\?v=)|(watch\/)))|(youtu.be\/))([A-z0-9]{1,11}).+'
|
|
|
|
# Supported Vimeo formats:
|
|
# - http://(www.)vimeo.com/258651879
|
|
# - http://player.vimeo.com/video/258651879
|
|
|
|
class VimeoURLValidator(RegexValidator):
|
|
regex = r'https?:\/\/(player|www.)?vimeo.com\/([0-9]{1,11}).+'
|
|
|
|
class YouTubeOrVimeoValidator(RegexValidator):
|
|
regex = r'https?:\/\/(player.|www.)?(vimeo\.com|youtu(be\.com|\.be))\/(video\/|embed\/|watch\?v=|v\/)?([A-Za-z0-9]{1,11}).+'
|