WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/validate username

Description

Checks whether username is valid.

Note: 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.

Usage

<?php validate_username$username ?>

Parameters

$username
(string) (required) Username.
Default: None

Return Values

(boolean) 
Returns true if $username is valid, false if $username is invalid.

Examples

<?php
if (!empty($_POST['username']) && validate_username($_POST['username'])) {
  // Go ahead and save the user...
}
?>

Notes

Change Log

Since: 2.0.1

Source File

Before 3.0
validate_username() is located in wp-includes/registration.php.

After 3.0
validate_username() is located in wp-includes/user.php.

Related

See also index of Function Reference and index of Template Tags.