dark 0 Report post Posted January 27, 2005 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
no9t9 0 Report post Posted January 27, 2005 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
bjrn 0 Report post Posted January 29, 2005 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
stevey 0 Report post Posted January 29, 2005 (edited) 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 January 30, 2005 by stevey (see edit history) Share this post Link to post Share on other sites
bjrn 0 Report post Posted January 29, 2005 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. Share this post Link to post Share on other sites
dark 0 Report post Posted January 30, 2005 HiThanks a lot guys, the first example will do me fine.Patrick Share this post Link to post Share on other sites
stevey 0 Report post Posted January 30, 2005 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
spirit_valley 0 Report post Posted January 30, 2005 I guess dark has his/her own reasons not to use regular expressions, so let us just forget about it. Share this post Link to post Share on other sites
karlo 0 Report post Posted February 5, 2005 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