Keep updating the username suggestion until they focus that field. Of course we don't mess with existing usernames.
323329
function updateUsername() {
      var $username = $el.findByName('username');
      if ((!usernameFocused) && (snippet.username === undefined)) {
        var username = apos.slugify($firstName.val() + $lastName.val());
        $.post(self._action + '/username-unique', { username: username }, function(data) {
          $username.val(data.username);
        });
      }
      $username.on('focus', function() {
        usernameFocused = true;
      });
    }
388979
def clean_username(self):
        
        try:
            get_user_model().objects.get(
                username__iexact=self.cleaned_data['username'])
        except get_user_model().DoesNotExist:
            pass
        else:
            raise forms.ValidationError(_('This username is already taken.'))
        if self.cleaned_data['username'].lower() in accounts_settings.ACCOUNTS_FORBIDDEN_USERNAMES:
            raise forms.ValidationError(_('This username is not allowed.'))
        return self.cleaned_data['username']
1075490
def is_username_available(self, username):
        """"""
        params = {'user': username}
        try:
            result = self.request_json(self.config['username_available'],
                                       params=params)
        except errors.BadUsername:
            return False
        return result
107670
def check_username_uniqueness(self, username):
        
        log.info("[+] Checking for Uniqueness of username '{}'".format(username))
        return self._send_xmpp_element(sign_up.CheckUsernameUniquenessRequest(username))
827606
@POST
  @Path("{id}/username")
  @RolesAllowed({"ROLE_ADMIN"})
  public Response changeUsername(@PathParam("id") Long id, UsernameRequest usernameRequest) {
    checkUsernameFormat(usernameRequest.username);

    userService.changeUsername(id, usernameRequest.getUsername());

    return Response.ok(id).build();
  }
379863
private function findNonExistingUserName()
    {
        for ($i = 0; $i < 20; ++$i) {
            $username = uniqid('User#', true);
            if (!$this->checkUserExistenceByUsername($username)) {
                return $username;
            }
        }

        throw new \Exception('Possible endless loop when attempting to find a new name for User.');
    }
240182
def username_validator(self, form, field):
        
        username = field.data
        if len(username) < 3:
            raise ValidationError(
                _('Username must be at least 3 characters long'))
        valid_chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._'
        chars = list(username)
        for char in chars:
            if char not in valid_chars:
                raise ValidationError(
                    _("Username may only contain letters, numbers, '-', '.' and '_'"))
248720
def release_name(self, username):
        
        self.temp_names.append(username)
        if self.is_username_used(username):
            self.registered_names.remove(username)
61474
public function afterFind()
    {
        parent::afterFind();
        $this->username_is_temporary = boolval($this->username_is_temporary);
        $this->is_active = boolval($this->is_active);
    }
460030
public void addUsername(String username) {
        SystemAssert.requireArgument(username != null && !username.isEmpty(), "Username cannot be null or empty.");
        this.usernames.add(username);
    }
150783
private function AddNameField()
    {
        $name = 'Name';
        $this->AddField(Input::Text($name, $this->page->GetName()));
        $this->SetRequired($name);
        $this->AddValidator($name, DatabaseCount::UniqueFieldAnd($this->page, $name, $this->SiteCondition()));
    }
795714
def validate_username_for_new_person(username):
    

    # is the username valid?

    validate_username(username)

    # Check for existing people

    count = Person.objects.filter(username__exact=username).count()
    if count >= 1:
        raise UsernameTaken(six.u(
            'The username is already taken. Please choose another. '
            'If this was the name of your old account please email %s')
            % settings.ACCOUNTS_EMAIL)

    # Check for existing accounts

    count = Account.objects.filter(username__exact=username).count()
    if count >= 1:
        raise UsernameTaken(six.u(
            'The username is already taken. Please choose another. '
            'If this was the name of your old account please email %s')
            % settings.ACCOUNTS_EMAIL)

    # Check account datastore, in case username created outside Karaage.

    if account_exists(username):
        raise UsernameTaken(
            six.u('Username is already in external account datastore.'))

    return username
1163084
protected function fillUsername(string $username): void
    {
        $this->context->findElement($this->fields['username'], $this->defaultTimeout)->setValue($username);
    }
1291292
function(usernames, rolename) {
    if (_.isEmpty(usernames)) {
      return Promise.reject(new Error('One or more usernames must be provided'));
    }

    if (!_.isArray(usernames)) {
      usernames = [usernames];
    }

    return Role.findOne({
        name: rolename
      })
      .populate('users')
      .then(function(role) {
        return User.find({
          username: usernames
        }, {
          select: ['id']
        }).then(function(users) {
          users.map(function(user) {
            role.users.remove(user.id);
          });
          return role.save();
        });
      });
  }
821707
def username(self, value):
        
        self._username = value
        self._connectionXML.set('username', value)
956460
protected boolean userAlreadyExists(String username) {

        if (m_user != null) {
            return false;
        }
        CmsUser user = null;
        try {
            user = m_cms.readUser(m_ou.getValue() + username);
        } catch (CmsException e) {
            return false;
        }

        return user != null;

    }
691070
function usernameIsUnique ( id ) {
        var deferred = q.defer();

        db.users.query( [ { key: 'identities.basic.username', cmp: '=', value: user.identities.basic.username } ] ,
            { limit: 1, skip: 0 } ).then(
                function ( payload ) {
                    if ( payload.total === 0 ) {
                        deferred.resolve();
                    }
                    else if( !_.isUndefined( id ) && payload.results[0]._id.toString() === id.toString() ) {
                        deferred.resolve();
                    }
                    else {
                        deferred.reject( new Error(messages.duplicate_username) );
                    }
                },
                function ( err ) {
                    deferred.reject( err );
                }
            );

        return deferred.promise;
    }