Delimiter //
/**
function cash_isNumber
Check if val could be cast to Number (float|Decimal|Integer)
**/

drop function if exists CASH_ISNUMBER//

create function CASH_ISNUMBER(val varchar(255), decimalChar char(1))
	returns int
Begin
    Declare decimalSep varchar(3);
    Declare pattern Varchar(80);

    if Coalesce(val, '') = '' Then
        return 1;
    End if;

    if decimalChar='.' Then
        Set decimalSep = '\\.';
    Else
        Set decimalSep = decimalChar;
    End If;

    Set pattern = concat('^(-|\\+){0,1}([0-9]+', decimalSep, '[0-9]*|[0-9]*', decimalSep, '[0-9]+|[0-9]+)$');

--    return val regexp '^(-|\\+){0,1}([0-9]+\\.[0-9]*|[0-9]*\\.[0-9]+|[0-9]+)$';
    return val regexp pattern;
End //

Delimiter ;
