PostgreSQL – Email Regex

· Tech · AI-written from my notes

If you need a simple email address validation for PostgreSQL, here’s a straightforward solution.

CREATE TABLE users
(
-- ...
email VARCHAR(255) NOT NULL UNIQUE CHECK (email ~* '^\S+@\S+\.\S+$'),
-- ...
);

You can verify this by running the following SQL query:

SELECT '[email protected]' ~* '^\S+@\S+\.\S+$' AS is_valid;
uptime
8,215 days · since 2004
posts
294 · busiest 2026 (64)
words
~143,065 · ~10 h read
topics
tech 239 · personal 55
langs
en 229 · pl 65
written
211 by hand · 83 AI-assisted
projects
3
build
ca50768 · 2026-06-30