Senin, 09 Februari 2009

PHP Form Validation

Pretty easy, eh? The table is not necessary, but it helps to make the form look nice. error.php
?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]+$/ ",$field_name_3))
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_phone))
{
echo "Illegal input $your_phone in 'your_phone'";
$error++;
}
if(!check_field3($your_zip))
{
echo "Illegal input $your_zip in 'your_zip'";
$error++;
}

if($error == 0)
{
echo
"
The data you entred was correct, thank you!


Your data:

Your name: $your_name

Your phone: $your_phone

ZIP code: $your_zip
";
}else{
echo "Number of errors: $error";
}

?

-----------------------------------------------

Related:


sqlserver2005-security
view information vb2005
write file in vb2005
Barcode-string-encoderVbnet
Changing-backgroundcolor
Trik finding google
Directly-filling control
Date-time format vb2008
Finding google rank
Domain checker phps cript
Foreign key sql2005
Create-insert-tableadapter
Check datagrid
Hapus error handling vb2008
Function2 vb2008