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
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 = 'some@email.address.com';
if (!checkEmail($email_to_check)) {
    echo 'the email address is not correct';
}
?>

 

Ken

 

Link to comment
Share on other sites

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;	
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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