php check valid username

You can check username is valid or not using regular expression.Regular expression is strong part of php.You can also use perl style of regular expression in php.The bellow given php function will allow only alpha numeric and underscore character.You can free to use this function in your project or scripts.

Function

function validate_username($username) {
    return preg_match('/^[A-Za-z][A-Za-z0-9]*(?:_[A-Za-z0-9]+)*$/',$username);
}

Leave a Reply

Your email address will not be published. Required fields are marked *