public function checkGroupname() {
    // Groupnames can either be constrained by username validation, or be an
    // email address.
    if (Tilmeld::$config['email_usernames']
        && $this->groupname === $this->email
      ) {
      return $this->checkEmail();
    }
    if (empty($this->groupname)) {
      return ['result' => false, 'message' => 'Please specify a groupname.'];
    }
    if (Tilmeld::$config['max_username_length'] > 0
        && strlen($this->groupname) > Tilmeld::$config['max_username_length']
      ) {
      return [
        'result' => false,
        'message' => 'Groupnames must not exceed '.
          Tilmeld::$config['max_username_length'].' characters.'
      ];
    }
    if (array_diff(
        str_split($this->groupname),
        str_split(Tilmeld::$config['valid_chars'])
    )) {
      return [
        'result' => false,
        'message' => Tilmeld::$config['valid_chars_notice']
      ];
    }
    if (!preg_match(Tilmeld::$config['valid_regex'], $this->groupname)) {
      return [
        'result' => false,
        'message' => Tilmeld::$config['valid_regex_notice']
      ];
    }
    $selector = ['&',
      'ilike' => [
        'groupname',
        str_replace(
            ['\\', '%', '_'],
            ['\\\\\\\\', '\%', '\_'],
            $this->groupname
        )
      ]
    ];
    if (isset($this->guid)) {
      $selector['!guid'] = $this->guid;
    }
    $test = Nymph::getEntity(
        ['class' => '\Tilmeld\Entities\Group', 'skip_ac' => true],
        $selector
    );
    if (isset($test->guid)) {
      return ['result' => false, 'message' => 'That groupname is taken.'];
    }

    return [
      'result' => true,
      'message' => (
        isset($this->guid) ? 'Groupname is valid.' : 'Groupname is available!'
      )
    ];
  }