calumogg
04-09-2008, 09:37 PM
Hey everyone, I know there is loads of stuff about PHP form validation on the net but I just cant get my head around it.
I am looking for a set of functions that will validate a email field, a purely text field (no numbers or characters), and finally one a field that has text, numbers and characters.
Am I on the right lines with this:
<?php
function textandnumbers($field_name_1)
{
if(!preg_match("/[^a-zA-Z0-9\.\-\Ä\ä\Ö\ö\Ü\ü\]+$/s",$field_name_1)){
$result = valid;
} else {
$result = notvalid;}
}
function text($field_name_2)
{
if(!preg_match("/[^a-zA-Z]+$/s",$field_name_2)){
$result = valid;
} else {
$result = notvalid;}
}
function numbers($field_name_3)
{
if(!preg_match("/[^0-9]+$/ ",$field_name_3)) {
$result = valid;
} else {
$result = notvalid; }
}
?>
I am looking for a set of functions that will validate a email field, a purely text field (no numbers or characters), and finally one a field that has text, numbers and characters.
Am I on the right lines with this:
<?php
function textandnumbers($field_name_1)
{
if(!preg_match("/[^a-zA-Z0-9\.\-\Ä\ä\Ö\ö\Ü\ü\]+$/s",$field_name_1)){
$result = valid;
} else {
$result = notvalid;}
}
function text($field_name_2)
{
if(!preg_match("/[^a-zA-Z]+$/s",$field_name_2)){
$result = valid;
} else {
$result = notvalid;}
}
function numbers($field_name_3)
{
if(!preg_match("/[^0-9]+$/ ",$field_name_3)) {
$result = valid;
} else {
$result = notvalid; }
}
?>