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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.