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 'test@example.com' ~* '^\S+@\S+\.\S+$' AS is_valid;