How can I make sure my function only works with inputs with a certain length?
for example:
I want my function to work with ID´s that have at least the length 3 but not more than 8?
As explained in this SO answer, you can define your own function that returns error message and call it from the validation function to return an error, e.g.:
CREATE FUNCTION F_PROCESS(ID VARCHAR(8)) RETURNS VARCHAR
BEGIN
DECLARE RETURN_VAR VARCHAR DEFAULT "";
IF(LENGTH(ID) < 3) THEN
CALL raise_error('ID must have at least 3 characters')
END IF;
RETURN RETURN_VAR;
END;//
Here, LENGTH
function checks for the lower bound whereas declaration checks for the upper bound.