Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

[PHP] - Quick Question..

Namecheap AuctionsNamecheap Auctions
Spacemail by SpaceshipSpacemail by Spaceship
SpaceshipSpaceship
Watch

Eric

VIP Member
Impact
328
Hi,

I'm currently writing a script.. and in that script they have to supply an email etc.. and am looking for a way to validate the email. I was wondering if I used something like below... if it would work.

(This is my first time doing anything with validating an email etc, so please be kind, lol)

PHP:
$em = eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email);

if ($em != eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email))
{
  echo 'Sorry, you entered an invalid email address.';
} else {
$email = $em;
//Rest of script
}

If I'm doing something wrong, or If I'm doing something right.. let me know either way. Thanks! :)

-Eric
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Also, check the MX entries of the domain (use explode() to find the server) and if it is invalid, the server is down or the domain does not exist. www.php.net or google it.
 
0
Close
well i dont have a lot of experience with email validation, but after some research, i dont think you need the first definition of $em. instead of $em=eregi. here's what i think it shud be:

PHP:
<?

$em = "[email protected]";
$ereg=eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$", $em);
if (!$ereg) {
   echo($email . "is not a valid email!");
}
else{
$email=$em;}
?>

correct me if im wrong, uber php guys (or gals)
 
0
Close
Thanks compu I'll look into that, and thanks nasaboy, I got my way working though. :)

-Eric
 
0
Close
this is really simple, but you would probably want to expand on it:
PHP:
<?php
$email = '[email protected]';
if (preg_match("/(.+)\@(.+)\.(.+){2,4}$/", $email))
{
	echo "match";
}
else 
{
	echo "no match";
}
?>

also, i would recommend using any of the ereg functions because they are not binary safe.
 
0
Close
CatchedCatched

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Member card: see how many threads a member started
The member card now shows a Threads number, right after Posts. The member card is the box that opens when you point at a name. Profile...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back