Validate Text with REGEXTEST

Excel Formulas › Advanced

365 (2024+)REGEX

Does the text match a pattern — yes or no? REGEXTEST returns TRUE/FALSE, ideal for validating formats like emails, postal codes, or IDs in a single formula or a data-validation rule.


Quick formula: check whether A2 looks like an email:
=REGEXTEST(A2, "^[\w.]+@[\w.]+\.\w+$")
Returns TRUE if the whole pattern matches. The ^ and $ anchors require the entire cell to fit the shape.

Functions used (tap for the full reference guide):

The example

Flagging which entries match an email shape.

AB
1EntryValid?
2ann@dfwexcel.comTRUE
3not-an-emailFALSE

The formula

Pattern test, TRUE or FALSE:

=REGEXTEST(A2, "^[\w.]+@[\w.]+\.\w+$") // whole-cell email shape

How it works

REGEXTEST answers “does it match?”:

  1. Give it the text and a pattern; it returns TRUE if the pattern is found.
  2. Anchor with ^ (start) and $ (end) to require the whole cell to match a format, not just contain it.
  3. Combine with IF for a label: =IF(REGEXTEST(A2, pattern), "OK", "Check").
  4. Drop it into Data Validation → Custom to block entries that don’t match a required format.

Validate on entry: a Data Validation custom rule =REGEXTEST(A1, "^[A-Z]{2}-[0-9]{4}$") enforces a code format like “AB-1234” as people type. Far cleaner than chaining LEN/ISNUMBER/MID checks.

Try it: interactive demo

Live demo

Test text against a pattern.

Match:

Variations

Label OK / Check

Readable flag:

=IF(REGEXTEST(A2, p), "OK", "Check")

Data Validation rule

Custom validation:

=REGEXTEST(A1, "^[A-Z]{2}-[0-9]{4}$")

Contains a digit?

Simple test:

=REGEXTEST(A2, "[0-9]")

Pitfalls & errors

Anchor for whole-cell match. Without ^…$, REGEXTEST is TRUE if the pattern appears anywhere — “contains” not “equals.”

365 (2024+) only. Older Excel returns #NAME?.

Shape, not truth. A valid format isn’t a guarantee — a well-formed email can still be undeliverable.

Practice workbook

📊
Download the free Validate Text with REGEXTEST practice workbook
REGEXTEST examples (formula text + result) with label, validation-rule, and contains-digit variants, plus 4 challenges with answers. No sign-up required.

Frequently asked questions

How do I check if text matches a pattern in Excel?
Use =REGEXTEST(text, pattern), which returns TRUE/FALSE. Anchor with ^ and $ to require the whole cell to match. Requires Excel 365 (2024+).
How do I validate a code format as it's typed?
Put REGEXTEST in Data Validation → Custom, e.g. =REGEXTEST(A1, "^[A-Z]{2}-[0-9]{4}$") to enforce a format like AB-1234.
Why is REGEXTEST TRUE for partial text?
Without ^ and $ anchors it tests whether the pattern appears anywhere. Add the anchors to require an exact whole-cell match.

Stop fighting formulas. Learn them in a day.

This recipe is one of hundreds of real-world formulas we teach. Our Excel Formulas & Functions class covers lookups, logic, text, and dynamic arrays hands-on — live in Dallas–Fort Worth, Houston, Austin, Oklahoma City, Denver, or online.

See the Formulas & Functions Class

Related formulas: Validate email format · REGEXEXTRACT · Restrict input length

Function references: REGEXTEST