Hello!

I am trying to validate a form... I have some success, being able to prevent a blank variable, a variable less than 2 characters, or a varaible mroe than 35 characters.
I am not having luck preventing someone from entering a number in the name field though.. What am I doing wrong?

if(empty($fname))
{
die ("No first name entered! Press the BACK button and add a first name. ");
}
elseif ( (strlen($fname) < 2) || (strlen($fname) > 25))
{
die("Invalid first name!  Press the BACK button and edit the first name.");
}
elseif (eregi ("^[A-Z]+$", $_POST['fname']))
{
die("Invalid first name!  Press the BACK button and edit the first name.");
}

else
{

etc.

    You could use

    preg_match()

    .

    ...
    elseif (preg_match ("/\d/", $_POST['fname'])) 
    { 
    die("Invalid first name!  Press the BACK button and edit the first name."); 
    ...

    That will catch any numeric value in a name.

      Thank you kindly! Will try out both methods and keep in mind for future formage.

        Write a Reply...