Jump to content
xisto Community
dark

Ensuring That @ Is Present?

Recommended Posts

HiIs 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 guysPatrick

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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:

//$email is the variable with the email addressif (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.

Share this post


Link to post
Share on other sites

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.

<?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..
Edited by stevey (see edit history)

Share this post


Link to post
Share on other sites

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....

Share this post


Link to post
Share on other sites

Which of these are the best?

 

1st:

 

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:

 

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 addressif (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:

 

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...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.