Check username on regular characters

Views: 8 Last modified: August 03rd, 2011 Comments: 0

This snippet will check the input on regular characters. Allowed: a-z, A-Z, 0-9, underscore(_) and dot(.).

function check_username($name)
{
    $valid = false;
    if (preg_match('/^[a-zA-Z0-9_\-\.]{5,25}$/', $name))
    {
        $valid = true;
    }

    return $valid;
}

Example

if (check_username('MrX-Hell.boy')) echo 'valid!';
VN:F [1.9.13_1145]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.13_1145]
Rating: 0 (from 0 votes)

    Mail this!

    To: From:Sum {6+7} =  
    Anything to add ?

        You must be logged in to post a comment.