validate_username

Checks whether a username is valid.

Description

validate_username( (string) $username ); 

Parameters (1)

0. $username (string)
The username.

Usage

  1. if ( !function_exists( 'validate_username' ) ) { 
  2. require_once ABSPATH . WPINC . '/user.php'; 
  3.  
  4. // The username. 
  5. $username = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = validate_username($username); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/user.php  
  1. function validate_username( $username ) { 
  2. $sanitized = sanitize_user( $username, true ); 
  3. $valid = ( $sanitized == $username && ! empty( $sanitized ) ); 
  4.  
  5. /** 
  6. * Filters whether the provided username is valid or not. 
  7. * @since 2.0.1 
  8. * @param bool $valid Whether given username is valid. 
  9. * @param string $username Username to check. 
  10. */ 
  11. return apply_filters( 'validate_username', $valid, $username );