<html>
<head> sample</head>
<body>
<form action="form.php" method="post">
<table>
<tr><td width="75">Your name:</td>
<td width="144">
<input type="text" name="your_name"></td></tr>
<tr><td>Your area code</td><td>
<p><input type="text" name="your_code" size="1" maxlenght="3"></td></tr></p>
<tr><td>Number:</td><td>
<input type="text" name="your_number" method="post" maxlenght="7"></td></tr>
<tr><td>Zip code:</td><td>
<input type="text" name="your_zip"></td></tr>
</table> <br>
<input type="submit">
</form>
</body>
</html>
<?php
extract($_POST);
/* Validation */
function check_field1($field_name_1)
{
if(!preg_match("/[^a-zA-Z0-9\.\-\Ä\ä\Ö\ö\Ü\ü\]+$/s",$field_name_1))
return TRUE;
else
return FALSE;
}
function check_field2($field_name_2)
{
if(!preg_match("/[^0-9\ ]+$/",$field_name_2))
return TRUE;
else
return FALSE;
}
function check_field3($field_name_3)
{
if(!preg_match("/[^0-9\ ]+$/"."(\d{3})[\-\.]?(\d{4})",$field_name_3)) /*how can we prevent the user to block their entry if its not 7 digits */
return TRUE;
else
return FALSE;
}
function check_field4($field_name_4)
{
if(!preg_match("/[^0-9]+$/ ",$field_name_4))
return TRUE;
else
return FALSE;
}
/* Validation */
$error=0; // check up variable
/* get it checking */
if(!check_field1($your_name))
{
echo "Illegal input $your_name in 'your_name'";
$error++; // $error=$error+1;
}
if(!check_field2($your_code))
{
echo "Illegal input $your_code in 'your_code'";
$error++;
}
if(!check_field3($your_number))
{
echo "Illegal input $your_number in 'your_number'"; /*how can we prevent the user to block their entry if its not 7 digits */
$error++;
}
if(!check_field4($your_zip))
{
echo "Illegal input $your_zip in 'your_zip'";
$error++;
}
if($error == 0)
{
echo
"
The data you entered was correct, thank you!<p>
Your data:<br>
Your name: $your_name<br>
Your Area code: $your_code<br>
Your phone: $your_number<br> /*how can we prevent the user to block their entry if its not 7 digits */
ZIP code: $your_zip
";
}else{
echo "Number of errors: $error";
}
?>