Formula Errors

Check Whether an Excel Cell Contains One Dash and Two Digits

Rana GarciaRana Garcia Nov 25, 2026 869 views

Question details

Check whether a cell contains exactly one dash followed by exactly two numeric digits.

Check Whether an Excel Cell Contains One Dash and Two Digits
Product
Microsoft Excel
Device & OS
not provided
Scenario
Validate text values and reject entries with extra dash-separated sections or nonnumeric suffixes.
Observed behavior
Valid entries should have one dash and end with two digits, such as ABC-12; invalid entries should be marked accordingly.
Before you start

Identify the column containing the values to check and choose an empty helper column for the results. The formula below checks A1; change that reference if your first value is in another cell.

Solution 1Recommended

Use a Formula to Validate the Dash and Two Digits in Excel

Use a helper column to mark each value as OK or Not OK.

The formula requires exactly one dash and exactly two digits after it. It permits text before the dash, but does not require it.

1
Select a result cell

Open the workbook in Excel and select B1, or another empty cell beside the value in A1.

2
Enter the formula

In B1, enter =IFERROR(IF(AND(LEN(A1)-LEN(SUBSTITUTE(A1,"-",""))=1,LEN(A1)-FIND("-",A1)=2,ISNUMBER(FIND(MID(A1,FIND("-",A1)+1,1),"0123456789")),ISNUMBER(FIND(MID(A1,FIND("-",A1)+2,1),"0123456789"))),"OK","Not OK"),"Not OK") and press Enter.

3
Check the remaining rows

Drag the fill handle from B1 down the helper column. Excel adjusts the A1 reference for each row.

4
Test the results

Enter ABC-12 in a source cell to test a valid value. Try ABC-12-34, ABC-1A, and ABC-123 to confirm they return Not OK.

Use a Formula to Validate the Dash and Two Digits in Excel
Require a prefix: The value -12 also returns OK. If a character must appear before the dash, add FIND("-",A1)>1 as another condition inside AND.
Validate values in WPS Spreadsheet

Check Dash-and-Digit Values in WPS Spreadsheet

Use a helper-column formula in WPS Spreadsheet to identify values with exactly one dash followed by two digits.

  1. 1. Open the spreadsheet: Launch WPS Spreadsheet and use Open to select your spreadsheet file.
  2. 2. Select a helper cell: Click B1, or an empty cell beside the first value. The formula below assumes the value is in A1.
  3. 3. Enter the validation formula: Enter =IFERROR(IF(AND(LEN(A1)-LEN(SUBSTITUTE(A1,"-",""))=1,LEN(A1)-FIND("-",A1)=2,ISNUMBER(FIND(MID(A1,FIND("-",A1)+1,1),"0123456789")),ISNUMBER(FIND(MID(A1,FIND("-",A1)+2,1),"0123456789"))),"OK","Not OK"),"Not OK") and press Enter.
  4. 4. Apply it to other rows: Drag the fill handle down the helper column to check the remaining values.
Mark invalid dash-and-digit patterns with a formula.Open and edit Microsoft Excel XLSX and XLS files.Use a familiar spreadsheet interface and fill formulas down a column.Work with spreadsheet files using the free version of WPS Office.
microsoft office alternative - wps office

Frequently Asked Questions

Does the formula require text before the dash?

No. Both ABC-12 and -12 return OK. To require at least one character before the dash, add FIND("-",A1)>1 inside the formula's AND function.

Will a value with two dashes pass the check?

No. The LEN and SUBSTITUTE condition counts the dashes, so ABC-12-34 returns Not OK.

Can the two characters after the dash be letters?

No. Each character after the dash must be found in 0123456789. For example, ABC-1A returns Not OK.

How do I check values starting in A2 instead of A1?

Enter the formula in an empty cell such as B2 and replace every A1 reference with A2. Then drag the fill handle down to check the other rows.