ALTER TABLE users ADD CONSTRAINT users_email_check
CHECK ( email ~ '\\A(?i-mx:[\w\.%\+\-]+)@(?i-mx:(?:[a-z0-9\-]+\.)+)(?i-mx:[a-z]{2,})\\Z' );
The above PostgreSQL column constraint gives:
ERROR: invalid regular expression: quantifier operand invalid
Note, the double backslash at Start and End of String anchors were necessary for escape because the statement is placed inside a heredoc.
email ~* '^(?:[\w.%+-]+)@(?:(?:[a-z0-9-]+\.)+)(?:[a-z]{2,})$'