All pastes #77588 Raw Edit

v3x

public php v1 · immutable
·published 2006-07-03 05:38 UTC
rendered paste body
function invalid_username($username){	$error_responses = array("Username can only contain the following: Letters aA-zZ, underscores, and spaces",		 "Username may not begin with a space or underscore (_)",		 "Username may not end with a space or underscore (_)",		 "Username may not contain more than two spaces anywhere",		 "Username may not contain more than two underscores (_) anywhere"	);	$MAX_ERRORS = count($error_responses);	$error = array();	for($i = 0; $i < $MAX_ERRORS; $i++)		$error[$i] = FALSE;	$error_str = "";	$len = strlen($username);	if(!preg_match("/^[a-zA-Z0-9 _]*$/", $username)) {		$error[0] = TRUE;	}	elseif($username{0} == ' ' OR $username{0} == '_') {		$error[1] = TRUE;	}	elseif($username{$len - 1} == '_' OR $username{$len - 1} == ' ') {		$error[2] = TRUE;	}	elseif(strpos($username , "  ") !== FALSE) {		$error[3] = TRUE;	}	elseif(strpos($username , "__") !== FALSE) {		$error[4] = TRUE;	}	for($i = 0; $i < $MAX_ERRORS; $i++)	{		if($error[$i])			$error_str .= red_message($error_responses[$i]) . (($i == $MAX_ERRORS) ? "" : "<br \>");	}	if(!empty($error_str))		return $error_str;	return FALSE;}