isNumeric static method

bool isNumeric(
  1. String? s
)

验证是否为纯数字(整数或小数)。

允许的形式:123、-123、12.3、-12.3、.5、0.0。 小数点后必须紧跟至少一位数字,因此 "123."(末尾孤立的小数点)会被拒绝。

Implementation

static bool isNumeric(String? s) {
  if (s == null || s.isEmpty) return false;
  const pattern = r'^-?(?:\d+(?:\.\d+)?|\.\d+)$';
  return hasMatch(s, pattern);
}