Skip to content

Instantly share code, notes, and snippets.

@savaged
Created August 17, 2022 10:46
Show Gist options
  • Select an option

  • Save savaged/8af31079c95d929cafba7c3e69232004 to your computer and use it in GitHub Desktop.

Select an option

Save savaged/8af31079c95d929cafba7c3e69232004 to your computer and use it in GitHub Desktop.
MySql custom function for checking if a string is intended to represent a number
DROP FUNCTION IF EXISTS `fn_isnumeric`;
DELIMITER //
CREATE FUNCTION `fn_isnumeric`(
s VARCHAR(100))
RETURNS TINYINT
NO SQL
BEGIN
RETURN IFNULL(s, '') REGEXP '^[:space:]*[+-]?[£\$\€]?([0-9]*\.?[0-9]+|[0-9]{1,3}(,[0-9]{3})*(\.[0-9]+)?)[:space:]*$';
END //
DELIMITER ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment