Are you human

i am working on a contact form and so far all is well but i need to know how can i create a function in php that requests the answer to be and only be “yes”?

i got a question that states 'are you human?" this isn’t the best way for security but it does trip some bots up.

also i have a phone number but i need the phone number to be in a specific format ie xxx-xxx-xxxx

how can i set it up? i found on google for email:

	if(trim($_POST['email']) == '')  {
		$hasError = true;
	} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\\.[A-Z]{2,4}$", trim($_POST['email']))) {
		$hasError = true;
	} else {
		$email = trim($_POST['email']);

but nothing on phone numbers. please help :frowning:

Are you human:
You don’t need a function to do it, simply have the form pass along the answer via post. And validate the post variable:

if ($_POST['answer'] == "yes") echo "good"; else echo "bad";

Phone number:
Use regex, but not the ereg family as it’s about to be eliminated from php 6, instead use preg

$number = "123-456-7890";

if (preg_match("/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/", $number)) echo "good"; else echo "bad";

thanks! i appreciate it!