Re: plpgsql function to validate e-mail

From: David Fetter <david(at)fetter(dot)org>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Andre Lopes <lopes80andre(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: plpgsql function to validate e-mail
Date: 2009-08-17 05:45:43
Message-ID: 20090817054543.GF3936@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Aug 17, 2009 at 06:43:54AM +0200, Pavel Stehule wrote:
> Hello
>
> 2009/8/16 Andre Lopes <lopes80andre(at)gmail(dot)com>:
> > Hi,
> >
> > I need a plpgsql function to validade e-mail addresses. I have google but I
> > can't find any.
> >
> > My question: Anyone have a function to validate e-mails?
> >
> > Best Regards,
> > André.
> >
>
> You don't need plpgsql. Important is only an using of regular expression.
>
> very strong validation should be done via plperlu
>
> CREATE OR REPLACE FUNCTION check_email(varchar)
> RETURNS boolean AS $$
> use strict;
> use Email::Valid;
> my $address = $_[0];
> my $checks = {
> -address => $address,
> -mxcheck => 1,
> -tldcheck => 1,
> -rfc822 => 1,
> };
> if (defined Email::Valid->address( %$checks )) {
> return 'true'
> }
> elog(WARNING, "address failed $Email::Valid::Details check.");
> return 'false';
> $$ LANGUAGE plperlu IMMUTABLE STRICT;

If the network interface can ever be down, this function is not in
fact immutable, as it will fail on data that it passed before.

Cheers,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
Skype: davidfetter XMPP: david(dot)fetter(at)gmail(dot)com

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Pavel Stehule 2009-08-17 05:50:14 Re: plpgsql function to validate e-mail
Previous Message Scott Marlowe 2009-08-17 05:27:21 Re: Generating random unique alphanumeric IDs