WordPress at a glance

validate_username() WP 1.0

Checks whether a username is valid.

  • Since 4.4.0 Empty sanitized usernames are now considered invalid
Works based on: sanitize_user()
Hooks from function:
Return

true/false. Whether username given is valid

Usage

validate_username( $username );
$username(string) (required)
Username.

Code of validate_username: wp-includes/user.php VER 4.9.8

<?php
function validate_username( $username ) {
	$sanitized = sanitize_user( $username, true );
	$valid = ( $sanitized == $username && ! empty( $sanitized ) );

	/**
	 * Filters whether the provided username is valid or not.
	 *
	 * @since 2.0.1
	 *
	 * @param bool   $valid    Whether given username is valid.
	 * @param string $username Username to check.
	 */
	return apply_filters( 'validate_username', $valid, $username );
}

Related Functions

From category: Other

No comments
    Hello, !     Log In . Register