Restrict Three-Digit Numbers to Specific Digits in Excel
Question details
Restrict entries to three-digit numbers composed only of selected digits.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A worksheet needs to accept three-digit numbers using only the digits 2, 3, 4, 5, and 6.
- Observed behavior
- Valid entries contain exactly three digits, each drawn from the permitted set.
Identify the cells that need the rule and decide which digits to permit. The example below uses A2:A100 and allows repeated digits from 2 through 6.
Create a Custom Excel Data Validation Rule
Use one formula to check the number and all three digits without a helper column.
In Excel, select A2:A100, or select your own input range with its top-left cell active.
Go to Data > Data Validation. On the Settings tab, choose Custom under Allow.
In the Formula box, enter =IFERROR(AND(ISNUMBER(A2),A2=INT(A2),A2>=100,A2<=999,ISNUMBER(FIND(MID(A2,1,1),"23456")),ISNUMBER(FIND(MID(A2,2,1),"23456")),ISNUMBER(FIND(MID(A2,3,1),"23456"))),FALSE). Replace A2 with the top-left cell of your selected range. To change the permitted digits, replace each occurrence of 23456 with the same desired digit set.
On the Error Alert tab, enable the alert and choose Stop. Add a message such as “Enter a three-digit number using only 2, 3, 4, 5, or 6,” then click OK.
Type 234 or 666 into a selected cell to test valid entries. Try 237, 23, and 234.5 to check that invalid entries are rejected.

Validate Three-Digit Entries in WPS Spreadsheet
Use a custom validation formula in WPS Spreadsheet to restrict entries to three-digit numbers made from your chosen digits.
- 1. Open the spreadsheet: Open WPS Spreadsheet and select the cells where users will enter numbers, such as A2:A100.
- 2. Open validation: On the Data tab, open Data Validation or Validity, depending on your WPS version, and choose Custom in the validation settings.
- 3. Enter the rule: Enter =IFERROR(AND(ISNUMBER(A2),A2=INT(A2),A2>=100,A2<=999,ISNUMBER(FIND(MID(A2,1,1),"23456")),ISNUMBER(FIND(MID(A2,2,1),"23456")),ISNUMBER(FIND(MID(A2,3,1),"23456"))),FALSE) in the formula field. Replace A2 with the top-left cell of your selected range.
- 4. Apply and test: Set a Stop-style error alert if available, confirm the rule, and test entries such as 234 and 237 in the selected cells.

Frequently Asked Questions
Can a permitted digit appear more than once?
Yes. The formula checks each position independently, so entries such as 222 and 666 are allowed.
How do I allow a different set of digits?
Edit the custom formula under Data > Data Validation and replace every occurrence of "23456" with the same desired set, such as "13579".
Why does the formula refer to A2 for the entire range?
A2 is a relative reference to the top-left cell of the selected range. Excel adjusts it for each cell where the validation rule applies.
Does the rule check values that were already in the cells?
It does not automatically remove existing invalid entries. In Excel, use Data > Data Validation > Circle Invalid Data to help identify values that do not meet the rule.




