Jump to content

Check textbox


Terfanda

Recommended Posts

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
Link to comment
https://forums.phpfreaks.com/topic/12459-check-textbox/
Share on other sites

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...
[code]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);[/code]
Link to comment
https://forums.phpfreaks.com/topic/12459-check-textbox/#findComment-47632
Share on other sites

[!--quoteo(post=385983:date=Jun 20 2006, 03:30 PM:name=SemiApocalyptic)--][div class=\'quotetop\']QUOTE(SemiApocalyptic @ Jun 20 2006, 03:30 PM) [snapback]385983[/snapback][/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
[code]
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);[/code]
[/quote]



this is what i am trying to do


[code]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();
              
                ?>[/code]
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
Link to comment
https://forums.phpfreaks.com/topic/12459-check-textbox/#findComment-47663
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.