# BuddyPress: Username Rules on the Sign-Up Form

> Requires BuddyPress usernames to be at least a few characters long and not just numbers, giving members a clear error message on the sign-up form.

- Type: PHP
- Runs: Run everywhere
- Category: [Users](https://wpide.com/library/category/users/)
- Tags: buddypress, registration, usernames
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/buddypress-username-rules/

## Code

```php
if ( ! function_exists( 'buddypress' ) ) {
    return;
}

$wpide_bp_username_min = 5;

add_filter( 'bp_core_validate_user_signup', function ( $result ) use ( $wpide_bp_username_min ) {
    if ( empty( $result['user_name'] ) || ! isset( $result['errors'] ) || ! is_wp_error( $result['errors'] ) ) {
        return $result;
    }

    $name = $result['user_name'];

    if ( strlen( $name ) < $wpide_bp_username_min ) {
        $result['errors']->add( 'user_name', sprintf( 'Usernames must be at least %d characters long.', $wpide_bp_username_min ) );
    } elseif ( ctype_digit( $name ) ) {
        $result['errors']->add( 'user_name', 'Usernames must contain at least one letter.' );
    }

    return $result;
} );
```

## Notes

BuddyPress already limits usernames to letters and numbers; this adds length and "not only digits" checks.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "BuddyPress: Username Rules on the Sign-Up Form" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
