[英]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)
For email and phone, I'd go here: 对于电子邮件和电话,我要去这里:
Phone: http://regexlib.com/DisplayPatterns.aspx?categoryId=7&cattabindex=6&AspxAutoDetectCookieSupport=1 电话: http : //regexlib.com/DisplayPatterns.aspx? categoryId=7& cattabindex=6&AspxAutoDetectCookieSupport=1
Email: http://regexlib.com/(A(llgnVic_ey1CZ-ARhYWF5QuIIWLB_e6dL5XiIJIyg6XJi02tVUo6G-L3wnj86Y6iAAoHxFNohNJupckHv1t4NZOxUY2-7EPAF80Lp5q96SMN10FzqKsTUj58iAOwyeNYbpecP25_crQt663bemwnIVb4EJijt_raaBeWYVnQiw7c1nSrQQ3W3PNoyopPWB6K0))/DisplayPatterns.aspx?cattabindex=0&categoryId=1 电子邮件: http://regexlib.com/(A(llgnVic_ey1CZ-ARhYWF5QuIIWLB_e6dL5XiIJIyg6XJi02tVUo6G-L3wnj86Y6iAAoHxFNohNJupckHv1t4NZOxUY2-7EPAF80Lp5q96SMN10FzqKsTUj58iAOwyeNYbpecP25_crQt663bemwnIVb4EJijt_raaBeWYVnQiw7c1nSrQQ3W3PNoyopPWB6K0))/DisplayPatterns.aspx?cattabindex=0&categoryId=1
You can use PHP's preg_match function to check them: http://php.net/manual/en/function.preg-match.php 您可以使用PHP的preg_match函数进行检查: http : //php.net/manual/zh/function.preg-match.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.