/**
 * Checks whether a passed extension number has valid sintax
 *
 * @param v_extension The extension to check format
 * @return %TRUE if it's well formated
 **/
DROP PROCEDURE IF EXISTS pbx.extensionIsValid;
DELIMITER $$
CREATE PROCEDURE pbx.extensionIsValid (vExtension VARCHAR(255))
BEGIN
	DECLARE vIsValid BOOLEAN;

	SET vIsValid =  vExtension IS NULL
		OR (vExtension REGEXP '^[0-9]{4}$'
		AND MOD(vExtension, 100) != 0);

	IF NOT vIsValid
	THEN
		SIGNAL SQLSTATE '45000'
			SET MESSAGE_TEXT = 'EXTENSION_INVALID_FORMAT';
	END IF;
END$$
DELIMITER ;
