Re: How to validate the email field?

From: Date: Thu, 02 Nov 2000 01:31:12 +0000
Subject: Re: How to validate the email field?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-23289@lists.php.net to get a copy of this message
On Wed, Nov 01, 2000 at 02:08:43PM -0600, sannec27@eng.uab.edu wrote: > Hello all, > > We are doing a survey on the network performance at UAB. In the survey form > provided to the users we are having an email field, which was declared as > varchar(25). Because of that even some body fills like 'ah:#@fhjk-@///kjdfr' > as their email address, our form is accepting it as a valid email field. So > we want to apply some validation while the user submits that form. Can any > one suggest us how we can apply this. Hi, I am not sure if the following snippet catches all invalid email address, as even ones that are syntactically correct can still be invalid and I can imagine some obscure addresses failing the following test, but still: if (!$email) $error .= "<LI>Your email address is missing\n"; elseif (!eregi("^([_a-z0-9-]+(\\.[_a-z0-9-]+)*)@([a-z0-9-]{2,}(\\.[a-z0-9-]{2,})*\\.[a-z]{2,3})$", $email)) $error .= "$email does not appear to be a valid email address<BR>\n"; else ...whatever... I hope this is of use to you. BTW, you might consider changing the varchar(25) field into something a bit bigger as I do know some people with email addresses long than that. Yours, -- Remco Rijnders, ICQ: 760542 | Linux adanidas 2.2.16 is up 26 days, 16:13 http://uss-centauris.org/ | Reporter: Mr Gandhi, what do you think of Phone: (+31) 70 3467809 | Western Civilization? Cellular: (+31) 6 22091723 | Gandhi: I think it would be a good idea.

« previous php.general (#23289) next »