Jump to content

Hi, I am a n00b and don't know how to write descriptive titles!


Recommended Posts

Hey.

 

Right...

 

How would i check if this string has a @ and a . in it? for example

 

<?php 

$email = "Yourface@lighthand.com";

if($email has a @ in the string and has a . in the string) { 
   echo "This has more possiblites of an email than without them";
}
else {
   echo "We could not tell if this is a email because there is no @ or dot";
}
?>

 

Point out the function or tell me how to do it :)

 

yeah... as Wuhtzu says,

 

or you could do two strstr's or look at following

http://uk3.php.net/manual/en/function.preg-match.php, this states that

"([-!#$%&'*+/=?_`{|}~a-z0-9^]

+(\.[-!#$%&'*+/=?_`{|}~a-z0-9

^]+)*|"([\x0b\x0c\x21\x01-\x08\

x0e-\x1f\x23-\x5b\x5d-\x7f]|\\[\x

0b\x0c\x01-\x09\x0e-\x7f])*")@((

[a-z0-9]([-a-z0-9]*[a-z0-9])?\.)+[

a-z0-9]([-a-z0-9]*[a-z0-9]){1,1}|

\[((25[0-5]|2[0-4][0-9]|[01]?[0-9]

[0-9]?)\.){3,3}(25[0-5]|2[0-4][0-9

]|[01]?[0-9][0-9]?|[-a-z0-9]*[a-z0

-9]:([\x0b\x0c\x01-\x08\x0e-\x1f\

x21-\x5a\x53-\x7f]|\\[\x0b\x0c\x0

1-\x09\x0e-\x7f])+)\])"

is the correct expression to use, lol


<?php
$EmailValString = '^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$' ;
if ( !eregi($EmailValString, $_POST['email']) ) :
    echo "This is not a valid email";
else : 
    echo "this is an acceptable formated email";
endif ; 

 

enjoy, ps reg came from zend so its sold

$email = $_POST['email'];

$checkemail = "/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i";
if(!preg_match($checkemail,$email)){
echo "E-mail is invalid\n";
}else {
echo "E-mail is valid";
}

I've always used this which I wrote but its probably not great, but i thought i would add it anyways

 

<?php
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[_a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email))
{ 
// False
} else
{
	// True
}
?>

 

~ Chocopi

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.