validate_username( string $username )
Checks whether a username is valid.
Description Description
Parameters Parameters
- $username
-
(string) (Required) Username.
Return Return
(bool) Whether username given is valid
Source Source
File: wp-includes/user.php
1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 | 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 ); } |
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
4.4.0 | Empty sanitized usernames are now considered invalid |
2.0.1 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
Example
if
( !
empty
(
$_POST
[
'username'
] ) && validate_username(
$_POST
[
'username'
] ) ) {
// Go ahead and save the user...
}