Jump to content

Recommended Posts

Hello,

i have a wierd problem, or maybe i'm just too tired to se it for myself :-)

 

$patterns = array(
                    "firstname"=>"/^[A-Za-Z-æøå]{2,64} [A-Za-zæøå]?$/",
                    "lastname"=>"/^[A-Za-zæøå-]{2,32}$/",
                    "adress"=>"/^[A-Za-zæøå\.]{5,32} [0-9]{1,5} [A-Za-zæøå0-9\.]?$/",
                    "city"=>"/^[A-Za-zæøå]{2,32}$/",
                    "postnr"=>"/^[0-9]{4,4}$/",
                    "tlf"=>"/^\+?[0-9]{8,10}$/",
                    "email"=>"[A-Za-z0-9._]{2,32}@[A-Za-z0-9]{2,32}\.[A-Za-z]{2,5}"
                    );

        foreach($_POST as $key => $value) {
            if($key !== "shipping" || $key !== "payment" || $key !== "next_x" || $key !== "next_y") {
                if(preg_match($patterns[$key], $value)) {
                    // do stuff..
                }
            }             
        }

 

It keeps ignoring my || operators, and checks the "trash" of my $_POST array?

Does anyone see why?

And please comment on my patterns, if you'd like :-)

 

Link to comment
https://forums.phpfreaks.com/topic/190723-operator-wont-work/
Share on other sites

I think you are falling into a common trap with or/not logic

 

you say if any of the conditions are not true, then do the preg_match, and seeing as they cannot all be true, then it will always do the match.

 

So I think your || should be &&

Link to comment
https://forums.phpfreaks.com/topic/190723-operator-wont-work/#findComment-1005792
Share on other sites

Hmm.. I'm having a hard time seeing any logic in that, but it sure helped, thanks :-)

 

in_array it returns true if the value is in the array, false otherwise. it just shortens if statements for me :P but it has many other uses :)

Link to comment
https://forums.phpfreaks.com/topic/190723-operator-wont-work/#findComment-1006300
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.