ctype_alnum() is a godsend for quick and easy username/data filtering when used in conjunction with str_replace().
Let's say your usernames have dash(-) and underscore(_) allowable and alphanumeric digits as well.
Instead of a regex you can trade a bit of performance for simplicity:
<?php
$sUser = 'my_username01';
$aValid = array('-', '_');
if(!ctype_alnum(str_replace($aValid, '', $sUser))) {
echo 'Your username is not properly formatted.';
}
?>