Checks whether a username is valid.
$usernamestringrequired
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.
function validate_username( $username ) {
$sanitized = sanitize_user( $username, true );
$valid = ( $sanitized === $username && ! empty( $sanitized ) );
/**
* Filters whether the provided username is valid.
*
* @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 );
}
Filters whether the provided username is valid.
© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/validate_username