Created
August 17, 2022 10:46
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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