hi
Does anyone know of a way to combine these two strings?
string one
elseif($_POST[“Phone”] == “” || $_POST[“Phone”] ==“Enter your phone number”)
{
header(“Location: Contact-us.html”);
exit;
}
#2
$phone = ‘000-0000-0000’;
if(preg_match(“/{3}-[0-9]{4}-[0-9]{4}$/”, $phone)) {
// $phone is valid
}
ralphm
December 21, 2011, 1:51am
2
What’s the reason for wanting to do that, as they seem to lead to different outcomes? I’m no expert at this, but normally I’m used to seeing all the error conditions grouped together that lead to one outcome, and all your success tests grouped together that lead to a different outcome.
EDIT: unless you want to add #2 to your list of failed conditions, in which you could do this:
elseif($_POST["Phone"] == "" || $_POST["Phone"] =="Enter your phone number" || [COLOR="#FF0000"]![/COLOR]preg_match("/^[0-9]{3}-[0-9]{4}-[0-9]{4}$/", $phone))
{
header("Location: Contact-us.html");
exit;
}
That is, the not symbol (!) is placed before preg_match for when it’s not a match.
i tried this (!totally slipped my mind)
got a syntax error
[quote="
[code"]
elseif($_POST[“Phone”] == “” || $_POST[“Phone”] ==“Enter your phone number” || ! preg_match(“/{3}-[0-9]{4}-[0-9]{4}$/”, $phone))
{
header(“Location: Contact-us.html”);
exit;
}
.
[/quote]
$phone = '000-0000-0000';
elseif($_POST["Phone"] == "" || $_POST["Phone"] =="Enter your phone number" || !preg_match("/^[0-9]{3}-[0-9]{4}-[0-9]{4}$/", $phone)
{
header("Location: Contact.html");
exit;
}
any ideas?
ralphm
December 21, 2011, 2:38am
4
Did you try my version? I had an extra closing parenthesis after $phone:
elseif($_POST[“Phone”] == “” || $_POST[“Phone”] ==“Enter your phone number” || !preg_match(“/{3}-[0-9]{4}-[0-9]{4}$/”, $phone))
You need to close off two parentheses - the one after elseif and the one after preg_match.
still not working
– unexpected T_ELSEIF??
any ideas?
$phone = ‘000-0000-0000’;
elseif($_POST[“Phone”] == “” || $_POST[“Phone”] ==“Enter your phone number” || !preg_match(“/{3}-[0-9]{4}-[0-9]{4}$/”, $phone))
{
header(“Location: Contact-us.html”);
exit;
}
ralphm
December 21, 2011, 3:33am
6
elsif really doesn’t belong on its own. You should have an if condition before this, and put the $phone variable earlier. Is the if condition there but just not posted here?