src/org/ohmage/validator/UserValidators.java
public static String validateUsernamePrefix(final String usernamePrefix) 
			throws ValidationException {
		
		// change minimum length to 2 instead of 4 in username
		String usernamePrefixString = USERNAME_PATTERN_STRING.replace("4", 
				String.valueOf(UserSetupRequest.MIN_USERNAME_PREFIX_LENGTH));
		Pattern usernamePrefixPattern = Pattern.compile(usernamePrefixString);

		
		if(StringUtils.isEmptyOrWhitespaceOnly(usernamePrefix)) {
			return null;
		}
		
		if(usernamePrefixPattern.matcher(usernamePrefix).matches()) {
			return usernamePrefix;
		}
		else {
			throw new ValidationException(
					ErrorCode.USER_INVALID_USERNAME, 
					"The username prefix is invalid.");
		}
	}
/**
	 * Validates that a given username prefix follows our conventions. If it is null 
	 * or whitespace only, null is returned. If it doesn't follow our 
	 * conventions, a ValidationException is thrown. Otherwise, the username prefix is
	 * passed back to the caller.
	 * 
	 * @param username The username prefix to validate.
	 * 
	 * @return Returns null if the username is null or whitespace only. 
	 * 		   Otherwise, it returns the username.
	 * 
	 * @throws ValidationException Thrown if the username isn't null or 
	 * 							   whitespace only and doesn't follow our 
	 * 							   conventions.
	 */
Validates that a given username prefix follows our conventions. If it is null
or whitespace only, null is returned. If it doesn't follow our
conventions, a ValidationException is thrown. Otherwise, the username prefix is
passed back to the caller.

@param username The username prefix to validate.

@return Returns null if the username is null or whitespace only.
Otherwise, it returns the username.

@throws ValidationException Thrown if the username isn't null or
whitespace only and doesn't follow our
conventions.
Validates that a given username prefix follows our conventions . If it is null or whitespace only null is returned . If it doesn ' t follow our conventions a ValidationException is thrown . Otherwise the username prefix is passed back to the caller . @param username The username prefix to validate . @return Returns null if the username is null or whitespace only . Otherwise it returns the username . @throws ValidationException Thrown if the username isn ' t null or whitespace only and doesn ' t follow our conventions .
public static String validateUsernamePrefix(final String usernamePrefix) 
			throws ValidationException {
		String usernamePrefixString = USERNAME_PATTERN_STRING.replace("4", 
				String.valueOf(UserSetupRequest.MIN_USERNAME_PREFIX_LENGTH));
		Pattern usernamePrefixPattern = Pattern.compile(usernamePrefixString);
		if(StringUtils.isEmptyOrWhitespaceOnly(usernamePrefix)) {
			return null;
		}
		if(usernamePrefixPattern.matcher(usernamePrefix).matches()) {
			return usernamePrefix;
		}
		else {
			throw new ValidationException(
					ErrorCode.USER_INVALID_USERNAME, 
					"The username prefix is invalid.");
		}
	}
public static String validateUsernamePrefix ( final String usernamePrefix ) throws ValidationException { String usernamePrefixString = USERNAME_PATTERN_STRING . replace ( "4" , String . valueOf ( UserSetupRequest . MIN_USERNAME_PREFIX_LENGTH ) ) ; Pattern usernamePrefixPattern = Pattern . compile ( usernamePrefixString ) ; if ( StringUtils . isEmptyOrWhitespaceOnly ( usernamePrefix ) ) { return null ; } if ( usernamePrefixPattern . matcher ( usernamePrefix ) . matches ( ) ) { return usernamePrefix ; } else { throw new ValidationException ( ErrorCode . USER_INVALID_USERNAME , "The username prefix is invalid." ) ; } }
Validates that a given username prefix follows our conventions.
Validates that a given username prefix follows our conventions .
// change minimum length to 2 instead of 4 in username