Jump to content


Photo

Check textbox


  • Please log in to reply
2 replies to this topic

#1 Terfanda

Terfanda
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 20 June 2006 - 11:51 AM

Hello All ,

I have written this function in order to check if the user enters alphabetic characters or numeric;

function check_Name($Name,$FamName)
{
$Name_Pattern="^[a-zA-Z]+$";
if ((eregi("$Name_Pattern",$Name))AND(eregi("$Name_Pattern",$FamName)))
{
$ans2=TRUE;
}
else
{
$ans2=FALSE;
}
return $ans2;

}



I am calling this function through this :::
if(check_Name("$Name","$FamName")==TRUE)
{
$acc2=TRUE;
}else{
$acc2=FALSE;
}


But it is not working correctly can you help me
thank you

#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 20 June 2006 - 12:30 PM

As it stands, that piece of code won't print anything to the screen. I ran your code on my machine and it runs perfectly fine, giving me the expected output. What is it (not) doing for you?

I rewrote it for you though, you were going about it the long way a bit...
function check_Name($Name,$FamName) {
    $Name_Pattern = "^[a-zA-Z]+$";
    if((eregi($Name_Pattern,$Name)) && (eregi($Name_Pattern,$FamName))) {
        return TRUE;
    } else {
        return FALSE;
    }
}

$acc2 = check_Name($Name,$FamName);


#3 Terfanda

Terfanda
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 20 June 2006 - 01:52 PM

[!--quoteo(post=385983:date=Jun 20 2006, 03:30 PM:name=SemiApocalyptic)--][div class=\'quotetop\']QUOTE(SemiApocalyptic @ Jun 20 2006, 03:30 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
As it stands, that piece of code won't print anything to the screen. I ran your code on my machine and it runs perfectly fine, giving me the expected output. What is it (not) doing for you?

I rewrote it for you though, you were going about it the long way a bit
function check_Name($Name,$FamName) {
    $Name_Pattern = "^[a-zA-Z]+$";
    if((eregi($Name_Pattern,$Name)) && (eregi($Name_Pattern,$FamName))) {
        return TRUE;
    } else {
        return FALSE;
    }
}

$acc2 = check_Name($Name,$FamName);
[/quote]



this is what i am trying to do


function emailcheck($Email)
                     {
                                $email_pattern = '^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$';
                            if (eregi ($email_pattern, $Email) )
                                {
                                    $ans1 = TRUE;
                            }
                                else
                            {
                                $ans1 = FALSE;
                            }
                                return $ans1;
                    }


                            
                    
                    
                    function check_forFileds($Name,$FamName,$Email)
                    {
                       if((!$Name)||(!$FamName)||(!$Email))
                       {
                             print("Invalid Input\n");
                             $ans=FALSE;
                             }
                             else
                                 {
                                      $ans=TRUE;
                                  }
                      return $ans;
                      
                      }
                      function check_Name($Name,$FamName)
                      {
                          $Name_Pattern="^[a-zA-Z]+$";
                            if ((eregi("$Name_Pattern",$Name))AND(eregi("$Name_Pattern",$FamName)))
                                    {
                                        $ans2=TRUE;
                                    }
                            else
                                 {
                                      $ans2=FALSE;
                                  }
                      return $ans2;
                     
                    }
                        

            function HandleForm()
            {  
                        
                        $Name=$_POST['fname'];
                        $FamName=$_POST['lname'];
                        $Email=$_POST['mailaddress'];
                        $TheDate=date("j F Y H:i:s");
                        
                        
                            
                             
                                if(emailcheck("$Email")==TRUE)
                                {
                                     $acc=TRUE;
                                     }else{
                                     $acc=FALSE;
                                 }
                                 $acc1=check_forFileds("$Name","$FamName","$Email");
                                
                                if(check_Name("$Name","$FamName")==TRUE)
                                {
                                     $acc2=TRUE;
                                     }else{
                                     $acc2=FALSE;
                                 }
                                            
                                                        if (($acc==TRUE)AND($acc1==TRUE)AND($acc2==TRUE))
                                                        {
                                                            $CallFunction=WriteToFile("$Name","$FamName","$Email","$TheDate");
                                                            print("<b>Thank You For Your Support.</b>");
                                                        }
                                                    
                                                            else
                                                                {
                                                                    print("<b>Please enter a valid Input !\n</b>");
                                                                }
                    
                            }       
                            
                                            if(isset($_POST['BeenSubmitted']))
                                               {
                                                   HandleForm();
                                               }
                                           CreateForm();
               
                ?>
I check for the input each at a time using the functions then

then i AND the result if it true

i write to the file
but there is a logical error i think in the name character check

if anyone can help me
thank you




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users