简体   繁体   中英

PHP Validation. Multiple types - 1 variable

Ok so I have a php variable called $contact_id which is inputted from the POST method.

$contact_id = $_POST['contact_id']; 

I want this variable to either store a phone number or an email address. I know this isn't the best way to do things but I have to work with what I have been given.

I was thinking of having something like

if($output = checkEmailValidation($contact_id) == 1 || $output = checkPhoneValidation($contact_id) == 1)
{
//input into database
}
else
{
//display error message
}

checkEmailValidation($input)
{
//do something

return $whatever
}

checkPhoneValidation($input)
{
//do something

return $whatever
}

First of all would this work. Second of all what would I put in the functions to make this work.

Thanks.

Yes that will work, but you'll need extra parenthesis in your if statement:

if(($output = checkEmailValidation($contact_id)) == 1 || 
   ($output = checkPhoneValidation($contact_id)) == 1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM