vn-asterisk/sql/extension-is-valid.sql

24 lines
556 B
MySQL
Raw Normal View History

2016-04-24 11:23:34 +00:00
/**
* 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;
2016-04-24 11:23:34 +00:00
DELIMITER $$
CREATE PROCEDURE pbx.extensionIsValid (vExtension VARCHAR(255))
2016-04-24 11:23:34 +00:00
BEGIN
DECLARE vIsValid BOOLEAN;
2016-04-24 11:23:34 +00:00
SET vIsValid = vExtension IS NULL
OR (vExtension REGEXP '^[0-9]{4}$'
AND MOD(vExtension, 100) != 0);
2016-04-24 11:23:34 +00:00
IF NOT vIsValid
2016-04-24 11:23:34 +00:00
THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'EXTENSION_INVALID_FORMAT';
END IF;
END$$
DELIMITER ;