I've been trying to check if a string value starts with a numerical value or space and act accordingly, but it doesn't seem to be working. Here is my code:
private static function ParseGamertag( $gamertag )
{
$safetag = preg_replace( "/[^a-zA-Z0-9\s]+/", "", $gamertag ); // Remove all illegal characters : works
$safetag = preg_replace( "/[\s]+/", "\s", $safetag ); // Replace all 1 or more space characters with only 1 space : works
$safetag = preg_replace( "/\s/", "%20", $safetag ); // Encode the space characters : works
if ( preg_match( "/[^\d\s][a-zA-Z0-9\s]*/", $safetag ) ) // Match a string that does not start with numerical value : not working
return ( $safetag );
else
return ( null );
}
So hiphop112 is valid but 112hiphip is not valid. 0down is not valid.
The first character must be an alphabetical character [a-zA-Z].