'validate username'

def clean(self, username):

    if (self.skip_clean == True):
        return username
    if (hasattr(self, 'user_instance') and isinstance(self.user_instance, User)):
        if (username == self.user_instance.username):
            return username
    try:
        username = super(UserNameField, self).clean(username)
    except forms.ValidationError:
        raise forms.ValidationError(self.error_messages['required'])
    if (len(username) < settings.MIN_USERNAME_LENGTH):
        raise forms.ValidationError(self.error_messages['toshort'])
    if (self.required and (not username_re.match(username))):
        raise forms.ValidationError(self.error_messages['invalid'])
    if (username in settings.RESERVED_USERNAMES):
        raise forms.ValidationError(self.error_messages['forbidden'])
    try:
        user = self.db_model.objects.get(**{('%s' % self.db_field): username})
        if user:
            if self.must_exist:
                return username
            else:
                raise forms.ValidationError(self.error_messages['taken'])
    except self.db_model.DoesNotExist:
        if self.must_exist:
            raise forms.ValidationError(self.error_messages['missing'])
        else:
            return username
    except self.db_model.MultipleObjectsReturned:
        raise forms.ValidationError(self.error_messages['multiple-taken'])
