Fix #408: Reject invalid strings when parsing numbers