Stage 0 Draft / February 20, 2025

Number.isSafeNumeric

1 Number.isSafeNumeric ( input )

Note

This method determines if a string can be safely converted to a JavaScript Number (float64). A string is considered "safe numeric" if it meets ALL of the following criteria:

Format Rules:

  • Contains only ASCII digits (0-9) with optional single leading minus sign
  • Has at most one decimal point, must have digits on both sides (e.g. "0.1", not ".1" or "1.")
  • No leading zeros (except for decimal numbers < 1)
  • No whitespace or other characters allowed

Value safety:

When the isSafeNumeric method is called with argument input, the following steps are taken:

  1. If the type of input is not a String, return false.
  2. Let str be ? ToString(input).
  3. If str is empty or contains only whitespace, return false.
  4. If str contains any characters other than:
    • ASCII digits (0-9)
    • One decimal point
    • One leading minus sign return false.
  5. If str contains:
    • Leading zeros (except for decimal numbers < 1)
    • Leading decimal point without zero
    • Trailing decimal point
    • Multiple decimal points return false.
  6. Let mv1 be the mathematical value of str.
  7. If abs(mv1) > 253 - 1, return false.
  8. Let num be ? ToNumber(str).
  9. Let strResult be ? ToString(num).
  10. Let mv2 be the mathematical value of strResult.
  11. If mv1 is not equal to mv2, return false.
  12. return true.