# How to check if a cell contains only numbers in Excel

In Excel 365 use =REGEXTEST(A2,"^\d+$"); in Google Sheets =REGEXMATCH(A2,"^\d+$"). Both are TRUE only when every character is a digit.

**Excel:** `=REGEXTEST(A2,"^\d+$")` (Microsoft 365 only)

**Google Sheets:** `=REGEXMATCH(A2,"^\d+$")`

## Example

Sample data (row 1 is the header):

| A | B |
| --- | --- |
| ZIP (as text) | Digits only? |
| 55401 |  |
| 5540I |  |
| 55102-1234 |  |
| 53703 |  |
| 58102 |  |
| 0480 |  |

Formula in B2, filled to B7: `=REGEXTEST(A2,"^\d+$")`

Result: TRUE; FALSE; FALSE; TRUE; FALSE; TRUE

## 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.

## Other ways

- `=AND(ISNUMBER(--MID(A2,SEQUENCE(LEN(A2)),1)))`: 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.

## 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}$")`.

Every formula and result on this page was checked by running it in the Spreadsheet Practice formula engine on 2026-10-30.

Source: https://spreadsheetpractice.com/formulas/check-if-cell-contains-only-numbers
