youtubeUrlValidator static method

String? youtubeUrlValidator(
  1. String? url
)

Implementation

static String? youtubeUrlValidator(String? url) {
  if (url == null) return 'Please enter video link';
  String pattern =
      r'(http(s)??\:\/\/)?(www\.)?((youtube\.com\/watch\?v=)|(youtu.be\/))([a-zA-Z0-9\-_])+';
  RegExp regExp = RegExp(pattern);
  if (url.isEmpty) {
    return 'Please enter video link';
  } else if (!regExp.hasMatch(url)) {
    return 'Please enter a valid youtube video link';
  }
  return null;
}