Skip to content

Common regex patterns

Pick a pattern, check its examples and copy it for your language or framework.

Common Regex

What does it do?

It is a library of ready-made regular expressions for the validations every project needs: email, URL, Spanish DNI and NIE, IBAN, international and Spanish phone numbers, postal codes, strong passwords, dates, times, hex colours, IPv4 addresses, slugs, UUIDs and usernames.

Each pattern comes with:

  • A description of what it accepts and its limits.
  • Examples that should match and that should not, already tested.
  • An explanation of every part of the regex.
  • Copy for JavaScript/TypeScript, HTML, Zod, Angular and Python.
  • Buttons to open it in the Tester or the Builder to adapt it.

Tip

Validate in the browser for a quick response to the user, and always validate again on the server: a client-side regex can be bypassed.

Frequently asked questions

›Is a regex enough to validate an email address?

No. A regex can reject obvious typos, but the only real check is sending a confirmation email. The RFC 5322 grammar is far too permissive and complex to be useful in a form.

›Do these patterns validate DNI letters or IBAN checksums?

No, they validate the format. The DNI control letter (number modulo 23) and the IBAN checksum (modulo 97) need a couple of lines of code after the regex.

›Can I use them in HTML forms?

Yes. Choose HTML in Copy for: you get an input with the pattern attribute, without the ^ and $ anchors that the browser adds by itself.