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)
For email and phone, I'd go here:
Phone: http://regexlib.com/DisplayPatterns.aspx?categoryId=7&cattabindex=6&AspxAutoDetectCookieSupport=1
You can use PHP's preg_match function to check them: http://php.net/manual/en/function.preg-match.php
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.