top of page

You are learning Data Validation in MS Excel

How to validate data based on text patterns (e.g., phone numbers) in Excel?

There are two main approaches to validate data based on text patterns in Excel:

1. Data Validation with Criteria:

- While Excel doesn't have built-in text pattern matching functions, you can leverage data validation with criteria.
- Steps:
1. Select the cell(s) where you want to enforce data validation.
2. Go to the "Data" tab and click "Data Validation" in the "Data Tools" group.
3. In the "Settings" tab, set "Allow" to "Custom."
4. In the "Formula" box, enter a formula using logical operators and text functions to define your pattern. Here's an example for phone numbers:

```excel
=AND(LEN(A1)=10,NOT(ISERR(VALUE(A1)))) // Replace A1 with your cell reference
```

- This formula checks if the text length is 10 (modify for your specific phone number format) and ensures the entered value can be converted to a number using the `VALUE` function (prevents alphabetic characters).

5. You can customize the formula based on your desired text pattern. Explore functions like `LEFT`, `RIGHT`, `SEARCH`, and wildcards (* ?) for more complex patterns.
6. In the "Error Alert" tab, you can set a custom message to inform users if their input doesn't meet the criteria.
7. Click "OK" to activate data validation. Now, when users enter data in the selected cell(s), Excel will validate it based on your formula. If it doesn't match the criteria, an error message will appear.

2. Conditional Formatting with Text Functions:

- This method doesn't prevent invalid data entry, but it visually highlights cells that don't conform to your text pattern.
- Steps:
1. Select the cell range where you want to apply conditional formatting.
2. Go to the "Home" tab and click "Conditional Formatting" in the "Styles" group.
3. Choose "New Rule" and select "Format cells only that contain" under "Select a rule type."
4. In the "Format values where" section, choose "Text contains" or "Text does not contain" depending on your needs.
5. Enter your desired text pattern (e.g., phone number format).
6. Click the "Format" button and choose a formatting style (e.g., red fill) to highlight non-conforming cells.
7. Click "OK" to apply the rule. Now, cells with text not matching the pattern will be visually identified with your chosen format.

Note: These methods have limitations in handling complex text patterns. For advanced pattern matching and data validation, consider using VBA or add-ins that provide regular expression functionality within Excel.

bottom of page