PostgreSQL – Email Regex

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;

Spot something wrong?

Found a typo, a broken link, or something that could be better? I would love to hear from you. Drop me a message and I will fix it.