| | 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 |
|
|
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.
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.
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..
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.
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....
I guess dark has his/her own reasons not to use regular expressions, so let us just forget about it.
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...
|
|
![]() 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 |
|