Jump to content

Need help with if, elseif and else statements..


pappakaka

Recommended Posts

I can't get these two if, elseif and else statements too work, here is the code:

    if(empty($this->password)){
      $this->errors[] = 'You must enter a password!';
  }
elseif(!strlen($this->password) >= 6){
  $this->errors[] = 'Your password must be longer than 6 characters!';
  }

    if(empty($this->email)){
      $this->errors[] = 'You must enter an email address!';
  }
elseif(!preg_match('/^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}$/',$this->email)){
  $this->errors[] = 'Your password can only contain these characters: a-z, A-Z and 0-9!';
  }

if(empty($this->confemail)){
      $this->errors[] = 'Please confirm your email address!';
  }
elseif(!$this->confemail == $this->email){
  $this->errors[] = 'The email addresses you entered did not match!';
  }

 

The if and elseif statements for "email" work just fine but the other 2 doesn't.

 

With the "password" i first want to check if the field is empty, and when it is, it works as it should. But when i for example type "test" too check if the password is longer than 6 characters i don't get any message at all?

 

With the "confemail" i want to first check if the field is empty, and when it is, it works as it should. But when i type in "test@test.com" in both fields to try to compare "confemail" to "email" i still get the "Please confirm your email address!" message?

 

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.