Postgres Function to Validate Email Address

前端 未结 6 2104
伪装坚强ぢ
伪装坚强ぢ 2021-01-02 09:30

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         


        
6条回答
  •  梦毁少年i
    2021-01-02 10:10

    I recommend a solution using PL/Perl and the Email::Address module. Something like the following:

    CREATE OR REPLACE FUNCTION email_valid(email text) RETURNS bool
    LANGUAGE plperlu
    AS $$
    use Email::Address;
    my @addresses = Email::Address->parse($_[0]);
    return scalar(@addresses) > 0 ? 1 : 0;
    $$;
    

    See also http://wiki.postgresql.org/wiki/Email_address_parsing.

提交回复
热议问题