US EIN (Tax ID) Regex

^[0-9]{2}-[0-9]{7}$

Validate US Employer Identification Number format XX-XXXXXXX.

Test This Pattern →

Pattern Breakdown

Understanding the regex pattern ^[0-9]{2}-[0-9]{7}$:

  • ^ - Start of string
  • $ - End of string
  • [...] - Character class
  • {n,m} - Quantifier (n to m times)

Examples

Input Result Explanation
12-3456789 ✓ Match Valid EIN
123456789 ✗ No Match Missing hyphen

Code Examples

JavaScript

JavaScript
const pattern = /^[0-9]{2}-[0-9]{7}$/;
const text = "12-3456789";

// Test if string matches
if (pattern.test(text)) {
  console.log("Valid!");
}

// Extract matches
const matches = text.match(pattern);
console.log(matches);

Python

Python
import re

pattern = r'^[0-9]{2}-[0-9]{7}$'
text = "12-3456789"

# Test if string matches
if re.match(pattern, text):
    print("Valid!")

# Find all matches
matches = re.findall(pattern, text)
print(matches)

PHP

PHP
<?php
$pattern = '/^[0-9]{2}-[0-9]{7}$/';
$text = "12-3456789";

// Test if string matches
if (preg_match($pattern, $text)) {
    echo "Valid!";
}

// Find all matches
preg_match_all($pattern, $text, $matches);
print_r($matches);
?>

Java

Java
import java.util.regex.*;

String pattern = "^[0-9]{2}-[0-9]{7}$";
String text = "12-3456789";

Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(text);

if (m.matches()) {
    System.out.println("Valid!");
}

Use Cases

Common applications: Business registration, tax forms, B2B verification

Frequently Asked Questions

What is the regex pattern for us ein (tax id) regex?
The regex pattern is: ^[0-9]{2}-[0-9]{7}$. Validate US Employer Identification Number format XX-XXXXXXX.
How do I use the us ein (tax id) regex pattern in JavaScript?
In JavaScript: const regex = new RegExp('^[0-9]{2}-[0-9]{7}$'); or const regex = /^[0-9]{2}-[0-9]{7}$/;
Does this pattern work in Python?
Yes, use: import re; pattern = re.compile(r'^[0-9]{2}-[0-9]{7}$') in Python. Most regex patterns are cross-language compatible.
What are common use cases for us ein (tax id) regex?
Business registration, tax forms, B2B verification

Related Regex Patterns

More Regex Tools

GetDevUtils offers a suite of developer tools including: