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 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 *

This site uses Akismet to reduce spam. Learn how your comment data is processed.