DROP PROCEDURE IF EXISTS account.user_checkName;

DELIMITER $$
CREATE DEFINER=`root`@`%` PROCEDURE `account`.`user_checkName`(vUserName VARCHAR(255))
BEGIN
/**
 * Checks that username meets the necessary syntax requirements, otherwise it
 * throws an exception.
 * The user name must only contain lowercase letters or, starting with second
 * character, numbers or underscores.
 */
	IF vUserName NOT REGEXP '^[a-z0-9_-]*$' THEN
		SIGNAL SQLSTATE '45000'
			SET MESSAGE_TEXT = 'INVALID_USER_NAME';
	END IF;
END$$
DELIMITER ;
