Jump to content

Function IF statement question


dk4210

Recommended Posts

Hello Guys,

 

I have a question about doing an IF statement in a function.

 

Here is my code

 

function checkEmail($email){
  return preg_match('/^\S+@[\w\d.-]{2,}\.[\w]{2,6}$/iU', $email) ? TRUE : FALSE;
}

 

How would I do the IF statement to test if the email is True or False?

 

Is it like this?

 

function checkEmail($email){
  return preg_match('/^\S+@[\w\d.-]{2,}\.[\w]{2,6}$/iU', $email) ? TRUE : FALSE;

if ($email == "False") {
Do something here
}

}

 

Thanks for you help!

Link to comment
https://forums.phpfreaks.com/topic/234069-function-if-statement-question/
Share on other sites

No, the return statement in the function ends the execution of the function. You check the validity of the email address by calling the function:

<?php
function checkEmail($email){
  return preg_match('/^\S+@[\w\d.-]{2,}\.[\w]{2,6}$/iU', $email) ? TRUE : FALSE;
}

$email_to_check = '[email protected]';
if (!checkEmail($email_to_check)) {
    echo 'the email address is not correct';
}
?>

 

Ken

 

Thanks for the quick response Ken. What if I wanted to check to just make sure that it's a valid email address in the function. Not necessarily a specific email address?

 

For example here is one I done for the price

 

function check_Price($price,$member_id,$description,$ip){
if (!is_numeric($price))
{
       $t_error="6";
   $member_id = $member_id;
	notify_Admin($t_error,$member_id,$ip);				
	logOut ($t_error);
	exit;	
}

Archived

This topic is now archived and is closed to further replies.

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