Well there seems to be a solution already, but here's a way of doing it I came up with. It's a bit more code.
PHP Code:
<?php
$alphas =
array( "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z",
"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
"1","2","3","4","5","6","7","8","9","0",".","_");
$badfirsts=array( "1","2","3","4","5","6","7","8","9","0",".","_");
$username="user._1234";
$n=0;
$OK=0;
$badchar=0;
// make sure our name is more then 2 characters long. (redundant to vB code if min can be set to two )
if (strlen($username)< 2 ) {
//eval("standarderror(\"".gettemplate("error_usernametooshort")."\");");
echo "exit on strlen < then 2";
exit;
}
// make sure the first char is not a space (redundant, not necessary)
if ($username[0] == " " ) {
//eval("standarderror(\"".gettemplate("error_usernametaken")."\");");
echo "exit on first char == space";
exit;
}
// check each charater for validity
while(strlen($username)>$n) {
foreach ($alphas as $c ){
if ( $c == $username[$n] ) {
$OK=1;
if ($n == 0 ){
foreach ( $badfirsts as $b ) {
if ( $b == $username[$n] ) {
$OK=0;
$badchar = 1;
}
}
}
if ( $OK || $badchar) {
break;
}
}
} // end for each alphas
// if charater not OK stop reg and show error page
// else reset OK var and increment counter to check next char
if ( !$OK ) {
//eval("standarderror(\"".gettemplate("error_usernametaken")."\");");
echo "exit on " . $username[$n] . " is not a valid char";
exit;
}
else {
$OK = 0;
echo $username[$n];
$n++ ;
}
} // end while
echo "exit NORMAL.";
?>
You can name it something.php and test the code on your site by playing with the $username var. There are echo statements for the errors to test it. The evals should be changed to point to a new template as pointed out in the other hacks if used.