简体   繁体   English

PHP验证。 多种类型-1个变量

[英]PHP Validation. Multiple types - 1 variable

Ok so I have a php variable called $contact_id which is inputted from the POST method. 好了,所以我是从POST方法输入的PHP变量名为$ CONTACT_ID。

$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语句中需要附加括号:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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