How to check if a cell contains only numbers in Excel
Excel formula
=REGEXTEST(A2,"^\d+$")In Excel 365 use =REGEXTEST(A2,"^\d+$"); in Google Sheets =REGEXMATCH(A2,"^\d+$"). Both are TRUE only when every character is a digit.
- Result on the example
- one result per row in
B2, filled down toB7 - Works in
- Microsoft 365 only
- Google Sheets
- Different formula, see below
See it work
The formula is already in B2, filled down to B7. Change any input and the result updates, or edit the formula to experiment.
How it works
In the pattern, ^ is the start of the text, \d+ one or more digits and $ the end, so the whole value has to be digits. "5540I" ends in a capital I, " 58102" starts with a space, and "55102-1234" has a dash, so they fail.
=REGEXTEST(A2,"^\d+$")ResultTRUE
A2"55401"The value in A2.
REGEXTEST(A2,"^\d+$")TRUEREGEXTEST: TRUE if the text contains a match for a regular expression.- text
A2"55401" - pattern
"^\d+$"
- text
In Google Sheets
Google Sheets needs a different formula: =REGEXMATCH(A2,"^\d+$"). On the same data it gives the same result. Here it is running in Google Sheets mode.
Other ways to do it
Each one was run on the same example sheet.
| Formula | Result | When to use it |
|---|---|---|
| =AND(ISNUMBER(--MID(A2,SEQUENCE(LEN(A2)),1))) | TRUE, FALSE, FALSE… | Excel 365 before REGEXTEST: split into characters and check that each one converts to a number. |
Common mistakes
ISNUMBER(--A2)is not the same test: it accepts "1,250", "1E3", "-4" and even dates like "3/14".- Without ^ and $, the pattern only needs one digit somewhere, so "5540I" would pass.
Try it yourself
Same data, empty answer cell. Your formula is graded instantly, then re-checked on changed data, so a typed-in number won't pass.
Check if a cell contains only numbers
B2, return TRUE when the cell contains nothing but digits and FALSE otherwise. Fill down to B7.Questions
How do I allow decimals?
Add an optional decimal part: "^\d+(\.\d+)?$".
How do I check for exactly 5 digits?
Use a count: =REGEXTEST(A2,"^\d{5}$").
Checked by running on 2026-10-30: every formula and result on this page was calculated by the Spreadsheet Practice formula engine, in both Excel and Google Sheets modes.