<?php
$name_first = strtolower($name_first = $_REQUEST['name_first']);
$name_last = strtolower($name_last = $_REQUEST['name_last']);
echo $reg_check = var_check($name_first, "name");
echo $reg_check = var_check($name_last, "name");
function var_check($var, $type)
{
# Resets the pattern string and the return string to nothing.
$pattern = "";
$return_string = "";
# Clears white spaces.
trim($var);
# Set up of patterns.
if ($type == "name"){ $pattern = "^[a-z]{1,10}$"; }
if ($type == "phone"){ $pattern = "^[0-9]{6}$"; }
if (!ereg ("$pattern", $var))
{
$return_string = "The entry <b>".$var."</b> is not valid, please check.";
}
return $return_string;
}
?>
Is this a good way of coding a regular expression?