validatePlaylistId static method

bool validatePlaylistId(
  1. String playlistId
)

Returns true if the given playlistId is valid.

Implementation

static bool validatePlaylistId(String playlistId) {
  playlistId = playlistId.toUpperCase();

  if (playlistId.isNullOrWhiteSpace) {
    return false;
  }

  // Watch later
  if (playlistId == 'WL') {
    return true;
  }

  // My mix playlist
  if (playlistId == 'RDMM') {
    return true;
  }

  // Playlist IDs vary greatly in length, but they are at least 2 characters long
  if (playlistId.length < 2) {
    return false;
  }

  return !RegExp(r'[^0-9a-zA-Z_\-]').hasMatch(playlistId);
}