<script> /** * @description Check whether a variable is a number * @author shuxiaokai * @create 2020-11-02 09:24 * @param {any} variable - Any type of variable * @return {Boolean} Returns true if it is a number, Otherwise return false * @remark * null NaN undefined => false * "0.2" "5" => false * Infinity => false */ isNumber(val) {if (val == null) { return false; } if (typeof val === "number" && Number.isFinite(val) && ! Number.isNaN(val)) { return true; } return false; }, * @author shuxiaokai * @create 2020-11-02 09:29 * @param {any} * @remark * null NaN undefined => false * Infinity => false * "0.2" "5" => true */ isNumberLike(val) { if (val.toString().match(/^-? (0 \ \ d + | 1 - [9] + \. \ | d + 1-9] [\ d {0, 20} | [0-9]) $/) | | this. IsNumber (val)) {return true; } return false; }, </script>Copy the code
From: github.com/trueleaf/mo…