Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3607654
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:24:10+00:00 2026-05-18T21:24:10+00:00

Here is my code: class FormValidator { private $firstname; private $lastname; private $email; private

  • 0

Here is my code:

class FormValidator {

    private $firstname;
    private $lastname;
    private $email;
    private $fields_with_lengths = array('first' => 2, 'last' => 2);
    private $color = '<span style="color:#FF0000">';

    function checkFirst($firstname) { 
        $first_error = NULL;
        if(strlen(trim($firstname)) < $this->fields_with_lengths['first']){
            $first_error = $this->color . 'Please enter more than ' . $this->fields_with_lengths['first'] . ' characters.</span>';
        }
        return $first_error;
    }

    function checkLast($lastname) {
        $last_error = NULL;
        if(strlen(trim($lastname)) < $this->fields_with_lengths['last']){
            $last_error = $this->color . 'Please enter more than ' . $this->fields_with_lengths['last'] . ' characters.</span>';
        }
        return $last_error;     
    }



    function validateEmail($email){
        return preg_match('/^[^@]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$/', $email);
    }


}

Here is where I call it:

$validator = new FormValidator();
                $firstResult = $validator->checkFirst($_POST['firstname']);
                $lastResult = $validator->checkLast($_POST['lastname']);
                $emailResult = $validator->validateEmail($_POST['emailaddress1']);

                if (is_null($firstResult) && is_null($lastResult) && $emailResult) {

                    $mail = new PHPMailer();

                    $mail->IsSMTP();  // telling the class to use SMTP
                    $mail->AddAddress("s...@....com");

                    $mail->Subject  = "test";
                    $mail->MsgHTML($messageHTML);

                    redirectULS('english/forms/thankyou.php');

                    if(!$mail->Send()) {
                        echo 'Message was not sent.';
                        echo 'Mailer error: ' . $mail->ErrorInfo;
                    } else {

                        //$bridge->pushLead($lead);
                    }
                } 

This only works if I remove $emailResult from the if statement. What am I doing wrong. I’ll take into account the earlier comments about functions that only return true or false later. Right now I need to fix this if statement. Thanks. (Some variables are set elsewhere. All I want to know here is how to get the if statement to work.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T21:24:11+00:00Added an answer on May 18, 2026 at 9:24 pm
    var_dump($firstResult, $lastResult, $emailResult);
    

    preg_match() returns the number of
    times pattern matches. That will be
    either 0 times (no match) or 1 time
    because preg_match() will stop
    searching after the first match.
    preg_match_all() on the contrary will
    continue until it reaches the end of
    subject. preg_match() returns FALSE if
    an error occurred.

    $email = "me@me.com";
    echo preg_match('/^[^@]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$/', $email); //1 (true)
    
    $email = "me+me.com";
    echo preg_match('/^[^@]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$/', $email); //0 (this is not false)
    
    $email = "me@me.com";
    if(1 == 1 && 0 == 0 && preg_match('/^[^@]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$/', $email)){
        echo "OK"; //yup
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here is my example code: Public Class Parent Private _TestProperty As String Private WithEvents
Here is a VB.NET code snippet Public Class OOPDemo Private _strtString as String Public
Here's my code: class Publisher(models.Model): name = models.CharField( max_length = 200, unique = True,
Ok, here is the code and then the discussion follows: public class FlatArrayList {
Edit: The code here still has some bugs in it, and it could do
See here: http://code.google.com/p/ie7-js/ Does anyone have any experience or remarks about this javascript? Is
I have this code here: var infiltrationResult; while(thisOption) { var trNode = document.createElement('tr'); var
We have some old C code here that's built with nmake. Is there an
I am using pseudo-code here, but this is in JavaScript. With the most efficient
I have a piece of code here that i really could use some help

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.