title: Simple regex for EU VAT-numbers
body: <p>I need a regex for validating EU-VAT numbers. There are some out there, but they are all specific to each member state and I do not need it to be so specific. So something that requires the user to enter a certain length of characters with first ones required to be letters, and rest digits with some letters allowed is good enough.</p>
  
  <p>So essentially I need to match following</p>
  
  <ul>
  <li>2-4 first characters must be letters</li>
  <li>The rest can either be digits only, or contain max 2 letters among the digits</li>
  <li>Ignore hyphens (some member states use them)</li>
  <li>Ignore spaces and underscores (because users)</li>
  </ul>
  
  <p>So far I have the following, which kind of does the job, but unfortunately also matches input with only letters (ABCDEFGHIJKLMNOP) <a href="https://regex101.com/r/KFME3H/2" rel="nofollow noreferrer">link</a></p>
  
  <pre><code>([A-Za-z]{2,4})([a-zA-Z0-9\-\_ ]{2,12})
  </code></pre>
  
  <p>Here you can see the format of all the VAT numbers.
  <a href="https://www.gov.uk/guidance/vat-eu-country-codes-vat-numbers-and-vat-in-other-languages" rel="nofollow noreferrer">https://www.gov.uk/guidance/vat-eu-country-codes-vat-numbers-and-vat-in-other-languages</a></p>