You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

美国联邦税号(EIN)正则修正请求:禁止全相同数字格式

Updated EIN Validation Regex (Blocks All Identical Digits)

Got it, let's fix that EIN validation regex for you. Your original pattern correctly enforces the IRS's valid prefix rules and basic format, but it misses checking for invalid all-identical-digit entries like 11-1111111 or 222222222. Here's the adjusted regex that addresses this gap:

<input type="text" pattern="^(?![0-9]{9}$|^(\d)\1-?\1{7}$)([07][1-7]|1[0-6]|2[0-7]|[35][0-9]|[468][0-8]|9[0-589])-?\d{7}$" />

Breakdown of the Changes

The key addition is the negative lookahead at the start, which explicitly blocks invalid all-same-digit cases:

  • (?![0-9]{9}$): Rejects 9-digit strings where every digit is identical (no hyphen, e.g., 222222222)
  • ^(\d)\1-?\1{7}$: Rejects strings where the first two digits match, and all seven trailing digits also match that same digit (with or without a hyphen, e.g., 11-1111111)

The rest of the regex retains your original validations:

  • ([07][1-7]|1[0-6]|2[0-7]|[35][0-9]|[468][0-8]|9[0-589]): Ensures the first two digits follow IRS-approved EIN prefix rules
  • -?: Allows an optional hyphen between the second and third digits
  • \d{7}: Matches the required seven trailing digits

Test Cases

  • Valid Entries: 12-3456789, 01-2345678, 99-8765432
  • Invalid Entries (Now Blocked): 11-1111111, 555555555, 77-7777777

内容的提问来源于stack exchange,提问作者Nirav Majevadiya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 09:57:21