validate_username( string $username ): bool

Checks whether a username is valid.

Parameters

$usernamestringrequired
Username.

Return

bool Whether username given is valid.

More Information

This function attempts to sanitize the username, and if it “passes”, the name is considered valid. For additional logic, you can use the ‘validate_username‘ hook.

Source

 * @since 2.0.0
 *
 * @param string $username The username to check for existence.
 * @return int|false The user ID on success, false on failure.
 */
function username_exists( $username ) {
	$user = get_user_by( 'login', $username );
	if ( $user ) {
		$user_id = $user->ID;
	} else {
		$user_id = false;
	}

	/**

Changelog

VersionDescription
4.4.0Empty sanitized usernames are now considered invalid.
2.0.1Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.