Regex Help

Can I have some help with regex. I’m using mod_rewrite for a social networking site, and I want to make sure every user name can be accounted for. Here is my current code.

^/([A-Za-z]+,[0-9]+)$ /user.php?id=$1

That will cover any username in the format “AbCaBc123”, but I also want it to include periods, underscores, letters, and numbers anywhere in the user name. Can someone show some code that will do that?

Also, how can I restrict my registration form/MySQL database to only allow #'s, letters, and “.” or “_”?

Thanks for the help!

Here is the user name part of my registration code.

$resultUser = mysql_query(
    sprintf(
        "SELECT Username FROM sq_users WHERE Username = '%s'",
        mysql_real_escape_string($_POST['user'])
    )
);
if(0 !== mysql_num_rows($resultUser)){
    header('Location: '. $root . $name_use);
	mysql_close($con);
	exit;
}

Also, my browser doesn’t “rewrite” the URL. it says it can’t find the URL. I don’t know what’s wrong. Help?

RewriteEngine  on
RewriteRule ^/social/([^/]+)$ /user.php?user=$1

Replace
([A-Za-z]+,[0-9]+)
with
([^/]+)

As for the second part of your question, you will need to post your registration code here, because it is very different.s