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 8449567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:44:42+00:00 2026-06-10T10:44:42+00:00

Is this code a good fit for the strategy pattern? public function isValidEmail($email, $organization)

  • 0

Is this code a good fit for the strategy pattern?

public function isValidEmail($email, $organization)
{   
    switch ($organization) {
        case 'USAF':
        case 'Army':
        case 'USMC':
        case 'Navy':
        case 'SOCOM':
            return (preg_match('/[.]mil$/i', $email) === 1);
            break;

        case 'Federal Gov.':
            return (preg_match('/[.]gov$/i', $email) === 1);
            break;

        case 'State/Local Gov.':
            $regionCollection = Mage::getModel('directory/region')
                ->getResourceCollection()
                ->addCountryFilter(array('US'))
                ->load();

            $stateAbbr = array();

            // Cycle through state abbreviations for match
            foreach ($regionCollection as $region) {
                $stateAbbr[] = strtolower($region->getCode());
            }
            $states = implode('|', $stateAbbr);

            return (preg_match("/[\.|@]{1}($states){1}\.us$/i", $email) ===
            break;

        case 'USCG':
        case 'DOD':
        case 'Defense Industry':
            return true;
            break;

        default:
            return false;
            break;
    }
    // It got past somehow?
    return false;
}

I was assuming you could have a simple interface to define a validate method but I’m slightly confused on how to handle the two odd ball cases in the switch statement that return true/false w/ no email logic.

interface ValidInterface
{
    public function isValid($email);
}
  • 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-06-10T10:44:44+00:00Added an answer on June 10, 2026 at 10:44 am

    You’re on the right track with your validator interface (I would name it something more meaningful like EmailValidator). You can then create a mapping of organizations to validators and look this up when performing the validation:

    private $validators = array(
      'USAF' => new MilitaryEmailValidator(),
      'Army' => new MilitaryEmailValidator(),
      ...
      'Defense Industry' => new TrueEmailValidator()
    );
    
    public function isValidEmail($email, $organization) {
      if (isset($this->validators[$organization]))
        return $this->validators[$organization])->isValid($email);
    
      // default return
      return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this email sending code that does not show a chooser (good). How
I think the following might be a good fit for the Strategy pattern but
is this good code? can it be simplified somehow? SELECT u.id,u.title,u.title,u.first,u.last FROM (((tblusers u
I'm not good at t-sql, so I need help. I have this code I
How to make this subqueries to good-looking code? And I looking guides about SQL
//Good day. This is just a part of my source code. My main predicament
Good evening, I'm having an issue with Masonry. This is all my relevant code:
Good evening, I have been trying to wrap my head about this, below, code
This code disabled mouse scroll functionality, when i click on the document. $(document).on(click, function
This code below allows me to find the word error in all my files

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.