Jul 25, 2008

Ensuring That @ Is Present?

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

Ensuring That @ Is Present?

dark
Hi

Is there a PHP already made function to ensure that an email field in a form contains the @?
I don't want the whole validation including regular expression, just want to check if user has typed the @.

Thanks a lot guys

Patrick

Reply

no9t9
Just use the STRSTR(); function. This checks a string for a user specified substring.

Example.

strstr($email, '@');

It will return FALSE if it is not found and you can write your IF statement around that.

Goto php.net for more info.

Reply

bjrn
Why don't you want to use the regular expression? I'm just curious.







This bit is for people who want to check if an email address is valid using regex but don't know how:
CODE

//$email is the variable with the email address
if (eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$', $email)) {
   //do things because the address is valid
} else {
   //do things because the address is NOT valid
}

Note that you can edit it some more if you want to ensure that the domain name isn't longer than 63 character (or whatever the limit is). And you could theoretically check for every single valid tld if you have it in a list instead of "([a-zA-Z]{2,4})". In fact, you could theoretically look up the full domain name to see if it exists...

But this regex should be okay.

Reply

stevey
hey you reallyl need to use regular expressinos, and well if you dont want to validate the email address but only just want to check if there was an @ sign then you could use this bit of code.
CODE

<?php
$email="some email address";
preg_match("|@|",$email,$valid_email);
if (empty(count($valid_email))
{
echo "email address not valid";
exit;
}else
{
//the rest of your code
}
?>


that should do it..

Reply

bjrn
Uhm , stevey, he said he didn't want to use regex, so I think no9t9's solution would do just fine. Your solution uses regex.

Reply

dark
Hi

Thanks a lot guys, the first example will do me fine.

Patrick

Reply

stevey
well honestly with all the power in php , you really should start to learn regular expressions, i mean i used to hate them too, but jus a quick look at it and trust me you could do alot with, it, and well if you cant use regex then, you could easily just do the same with javascript....

Reply

spirit_valley
I guess dark has his/her own reasons not to use regular expressions, so let us just forget about it.

Reply

karlo
Which of these are the best?

1st:

CODE
Just use the STRSTR(); function. This checks a string for a user specified substring.

Example.

strstr($email, '@');

It will return FALSE if it is not found and you can write your IF statement around that.

Goto php.net for more info.


2nd:

CODE
Why don't you want to use the regular expression? I'm just curious.
This bit is for people who want to check if an email address is valid using regex but don't know how:
[CODE]
//$email is the variable with the email address
if (eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$', $email)) {
  //do things because the address is valid
} else {
  //do things because the address is NOT valid
}


Note that you can edit it some more if you want to ensure that the domain name isn't longer than 63 character (or whatever the limit is). And you could theoretically check for every single valid tld if you have it in a list instead of "([a-zA-Z]{2,4})". In fact, you could theoretically look up the full domain name to see if it exists...

But this regex should be okay.[/CODE]

3rd:

CODE
hey you reallyl need to use regular expressinos, and well if you dont want to validate the email address but only just want to check if there was an @ sign then you could use this bit of code.
[CODE]
<?php
$email="some email address";
preg_match("|@|",$email,$valid_email);
if (empty(count($valid_email))
{
echo "email address not valid";
exit;
}else
{
//the rest of your code
}
?>


that should do it..[/CODE]

Need your vote...

 

 

 


Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : ensuring


    Looking for ensuring, present

Searching Video's for ensuring, present
advertisement



Ensuring That @ Is Present?



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE