I have installed the npm install big-integer https://www.npmjs.org/package/big-integer to test if the number is in the specified range with this code:

isBigInt: function () {
var val = $(this).valueOf
var valor = bigInt(val);
var minimo = bigInt("-9223372036854775808");
var maximo = bigInt("9223372036854775807");
if (bigInt(val).greaterOrEquals(minimo) && bigInt(val).lesserOrEquals(maximo))
return true;
else
return false;
}
,
($input.hasClass("bigint") && !$input.isBigInt())

but when I compile the code appears the following message:

"JavaScript runtime error: Invalid integer: NaN"

Dani AI

Generated

The error "Invalid integer: NaN" happens because bigInt() is being given something that is not a plain decimal integer string. In 's first snippet var val = $(this).valueOf does not return the input text; it yields a function/reference, so bigInt(val) tries to parse a non-numeric value. In the second snippet var val = bigInt() creates a bigInt without a valid input and then re-parses it—both patterns can lead to an invalid input being passed into the parser.

Quick debugging checklist

  • Inspect the actual value before calling bigInt: console.log(typeof val, JSON.stringify(val)).
  • Get the input text correctly (for jQuery inputs use $(this).val(), or use this.value if this is a DOM input).
  • Validate the string (only optional leading sign and digits) and reject empty or non-digit strings before conversion.
  • Wrap library parsing in try/catch to avoid unhandled exceptions.

Safe, library-free validator (string comparison)

function isSigned64Bit(input) {
  var s = (typeof input === 'string') ? input : String(input || '');
  s = s.trim();
  if (!/^[+-]?\d+$/.test(s)) return false;

  var sign = s[0] === '-' ? -1 : 1;
  var digits = s[0] === '+' || s[0] === '-' ? s.slice(1) : s;
  digits = digits.replace(/^0+/, '') || '0';

  var MAX_POS = '9223372036854775807';
  var MAX_NEG = '9223372036854775808';

  if (digits.length < 19) return true;
  if (digits.length > 19) return false;
  return sign === 1 ? (digits <= MAX_POS) : (digits <= MAX_NEG);
}

If your runtime supports ES2020 BigInt, this is simpler and exact:

function isInSigned64Range(input) {
  if (typeof input !== 'string') input = String(input || '').trim();
  if (!/^[+-]?\d+$/.test(input)) return false;
  try {
    var x = BigInt(input);
    var min = -(1n << 63n);
    var max = (1n << 63n) - 1n;
    return x >= min && x <= max;
  } catch (e) {
    return false;
  }
}

Extra notes: always pass a validated string to big-integer/BigInt (avoid bigInt() with no args), check the exact method names in the library docs if you use library comparison methods, and log the raw input when you see "NaN" errors.

isBigInt: function () {
        var val = bigInt();
        if (bigInt(val.toString()).greaterOrEquals("-9223372036854775808") && bigInt(val.toString()).lesserOrEquals("9223372036854775807"))
            return true;
        else
            return false;
    }
    ,
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.