Regex to Match EAN Barcode Numbers

Validate EAN-8 or EAN-13 barcode numbers consisting of exactly 8 or 13 digits. Matches the European Article Number standard barcode format. Free regex tester.

Regular Expression

/^\d{8}$|^\d{13}$/

Token Breakdown

TokenDescription
^Anchors at the start of the string (or line in multiline mode)
\dMatches any digit (0-9)
{8}Matches exactly 8 times
$Anchors at the end of the string (or line in multiline mode)
|Alternation — matches the expression before OR after the pipe
^Anchors at the start of the string (or line in multiline mode)
\dMatches any digit (0-9)
{13}Matches exactly 13 times
$Anchors at the end of the string (or line in multiline mode)

Detailed Explanation

This regex validates European Article Number (EAN) barcodes in both 8-digit and 13-digit formats. Here is the token-by-token breakdown:

^ — Anchors the first alternative at the start of the string.

\d{8} — Matches exactly 8 digits for the EAN-8 format. EAN-8 is the compact barcode format used on small products where space is limited.

$ — Anchors at the end of the string for the first alternative.

| — Alternation operator separating the two valid formats.

^ — Anchors the second alternative at the start of the string.

\d{13} — Matches exactly 13 digits for the EAN-13 format. EAN-13 is the standard barcode format used worldwide on retail products.

$ — Anchors at the end of the string for the second alternative.

No flags are used since this validates a single numeric string.

EAN-13 consists of a country code (2-3 digits), manufacturer code, product code, and a check digit. EAN-8 is a shortened version with a country code, item reference, and check digit. The check digit in both formats uses a modulus-10 algorithm with alternating weights of 1 and 3.

ISBN-13 numbers (starting with 978 or 979) are a subset of EAN-13. UPC-A codes (12 digits) can be converted to EAN-13 by prepending a zero. Examples include: 4006381333931 (EAN-13) and 96385074 (EAN-8). This pattern validates the length and digit-only format but does not verify the check digit. It is useful for retail systems, inventory management, and product catalogs.

Example Test Strings

InputExpected
4006381333931Match
96385074Match
123456No Match
12345678901234No Match
400638133393ANo Match

Try It — Interactive Tester

//
gimsuy
No matches found.
Pattern: 16 charsFlags: noneMatches: 0

Ctrl+Shift+C to copy regex

Customize this pattern →