Click to See Complete Forum and Search --> : check if the "message" contains the "letter" @..


fat_bob
11-07-2006, 10:09 AM
Hi there!
I have a small problem, I have a filed which the users should post his/her e-mail in. But I dont want alot of e-mails that doesnt contains a "@" letter.
I have created an if statement and such...
the only thing is that I dont undertstand how I should do to let the code search for the "@" letter in her/his e-mail....
any ideas?

Litewebsite
11-07-2006, 11:00 AM
You can check valid email (read: valid email format) with a regular expresssion.

PHP functions
* Regular Expression Functions (POSIX Extended) (http://www.php.net/manual/en/ref.regex.php)
* Regular Expression Functions (Perl-Compatible) (http://www.php.net/manual/en/ref.pcre.php)

Regular expressions for checking email addresses can be found at Regular Expression Library (http://regexlib.com/Search.aspx?k=email) .

fat_bob
11-07-2006, 11:07 AM
<?
include 'config.php';

$con = mysql_connect($dbname,$dbuser,$dbpass);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
if ($_POST["email"]==TRUE and
echo "<center><h2>Your e-mail has been succesfully added!</center></h2>";
else
echo "your email is invalid!";
?>

This is my current code....im no pro so please show me where to change and how...

The idea was to create something after the "and" statement that checks if the variable "email" contains an "@" "letter".....anyone know how to do thats..and if you do the please post me the code :)

Thanks for trying to help me :)

The Little Guy
11-07-2006, 11:54 AM
if (preg_match("/\@\b/i", $_POST['email'])) {
echo "This is a valid email";
} else {
echo "Invalid Email";
}

fat_bob
11-07-2006, 03:16 PM
well i did try to put
if (preg_match("/\@\b/i", $_POST['email']))
infront of the "and" statement..but it seams like it has to be in a special order else it cant find the @ letter....the order is /@bi....but I want the script to search in her/his e-mail for the letter @ where ever she/he types it.

for example. if she/he types asdasd@asd.com as her/his e-mail...then the script should search for the @ letter in her/his email....

The Little Guy
11-07-2006, 03:22 PM
if (preg_match("/\@/i", $_POST['email'])) {
echo "This is a valid email";
} else {
echo "Invalid Email";
}

fat_bob
11-07-2006, 03:42 PM
kk ty:P:D
Solved it:D

The Little Guy
11-07-2006, 03:45 PM
Your welcome