What is an integer?

An integer is a whole number: positive, negative or zero, with no decimal part, such as 42, -7 or 0. Counts are integers, like the guests at a picnic or the items in a cart, and so are years, ages, page numbers and the IDs many databases give their rows.

Forms, URLs such as ?page=2, CSV files and config files deliver these values as text. A program checks that the text is a whole number before it converts it, since 2.5 or ten in a quantity field would break a calculation or a database insert.

Tool description

Type or paste a value into the Integer field, and the result shows as you type: "Integer is valid" or "Integer is not valid". Spaces and line breaks around a pasted value are ignored.

Minimum and Maximum start empty. Fill in one or both to require a number in that range, the limits included: with a minimum of 1 and a maximum of 10, both 1 and 10 pass, and 11 fails. Allow leading zeros starts on. Turn it off and 007 fails, while a single 0 still passes.

Numbers that pass

  • Digits with or without a plus or minus sign: 42, -7, +15
  • Zero, even with a sign: 0, -0, +0
  • Leading zeros, while Allow leading zeros is on: 007, -007
  • Numbers of any length, even beyond what 32-bit or 64-bit integer types hold

Numbers that fail

  • A decimal point, even with only zeros after it: 1.0, 5., .5
  • E notation: 1e5
  • Thousands separators and spaces inside: 1,000, 1 000
  • Prefixes of other number systems: 0x1F, 0o17
  • Words such as Infinity, and two signs, as in --5
  • Digits of other scripts, such as Arabic-Indic or full-width digits

Good to know

  • Of the checks for ordinary numbers, this one is the strictest: unlike the Float Validator, it rejects every decimal point and e notation.
  • To make sure a value fits a 32-bit signed integer, set Minimum to -2147483648 and Maximum to 2147483647.
  • Leading zeros don't make a number octal here: 010 counts as ten, so it fails a maximum of 9.
  • Minimum and Maximum compare very long numbers, past 15 digits, only roughly, because the browser rounds them.
  • To find out whether a whole number is even, or a multiple of another number, use the Divisibility Checker.

Features

  • Checks whole numbers with or without a sign
  • Optional minimum and maximum, both included
  • A setting to reject leading zeros
  • Results as you type, with no button to press
  • Runs in your browser, so nothing you type is sent anywhere