Re: simple email validation ereg
| From: | Clay Loveless | Date: | Sun, 02 Jun 2002 04:18:09 +0000 |
| Subject: | Re: simple email validation ereg | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-100284@lists.php.net to get a copy of this message | ||
Maybe I'm biased, but if you grab validateEmailFormat.php from
www.killersoft.com, you'd be able to do something as simple as this:
<?php
include("/path/to/validateEmailFormat.php");
$email = "foo@foo.foo";
$isValid = validateEmailFormat($email);
if($isValid) {
// do whatever you need to do
} else {
echo "sorry, that address isn't formatted properly.";
}
?>
validateEmailFormat.php is a translation of the Perl regular expression
that's widely considered to be the defintive test of a valid RFC822 address.
Can't go wrong with that. : )
-Clay
> From: Justin French <justin@indent.com.au>
> Date: Sun, 02 Jun 2002 14:13:40 +1000
> To: php <php-general@lists.php.net>
> Subject: [PHP] simple email validation ereg
>
> Hi,
>
> I know that there are more complex functions and classes out there for
> validating email address', but some of them do return "invalid" on
> *technically* valid, although uncommon email address', so all I want is a
> simple test for:
>
> (anything)@(anything) followed by 1 or more (.anything)
>
> ie
> foo@foo : invalid
> foo@foo.foo : valid
> foo@foo.foo.foo.foo.foo : valid
>
> i wish to allow ANYTHING really -- not just a-z,A-z,0-9,_,- technically
> spaces, brackets, and all sorts of crap are valid in the user portion of the
> email address :)
>
>
> this will return true for foo@blah.com foo@blah.com.au foo@foo.blah.com.au
> etc etc... i'm aware that the results will not necessarily BE valid email
> address', but at least they'll *look* like valid email address'.
>
> it's for a simple guestbook/message board where some creative people have
> put in "lalaland" or "myplace" as an email address, rather than entering
> something that at least LOOKS like a valid address, or optionally leaving
> the field blank.
>
> my aim will be to strip out anything that doesn't at least LOOK like like an
> email address.
>
>
> regards,
>
> justin french
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>