Dynadot โ€” .com Transfer

[PHP] - Quick Question..

NamecheapNamecheap
Watch
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
•••
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
•••
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
•••
Thanks compu I'll look into that, and thanks nasaboy, I got my way working though. :)

-Eric
 
0
•••
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
•••
Dynadot โ€” .com TransferDynadot โ€” .com Transfer
Appraise.net
Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomainEasy โ€” Zero Commission
DomDB
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back