A check constraint which would call a function to validate email addresses is not working fine for me.
CREATE OR REPLACE FUNCTION f_IsValidEmail(text) return
A bunch of these answers are close to the right way. These are the points for my submission.
I show two methods of how to do this the right on DBA.StackExchange.com. Both to check for the MX-record, and also using the HTML5 spec. Here is the short and sweet.
CREATE EXTENSION citext;
CREATE DOMAIN email AS citext
CHECK ( value ~ '^[a-zA-Z0-9.!#$%&''*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$' );
SELECT 'foobar@bar.com'::email;
SELECT CAST('foobar@bar.com' AS email);
For more information I highly suggest you read the answer in full. In the answer, I also show how you create a DOMAIN
over Email::Valid
, and explain why I no longer use that method.