salix/db/routines/pbx/procedures/sip_isValid.sql

22 lines
515 B
MySQL
Raw Permalink Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `pbx`.`sip_isValid`(vExtension VARCHAR(255))
BEGIN
/**
* Check if an extension has the correct format and
* throws an exception if it hasn't.
*
* @param vExtension The extension
*/
DECLARE vIsValid BOOL;
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 format is invalid';
END IF;
END$$
DELIMITER ;