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

  • Home
  • SEARCH
  • 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 7872497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:12:53+00:00 2026-06-03T02:12:53+00:00

I have to validate email through several validators. I have class( EmailValidator ) that

  • 0

I have to validate email through several validators. I have class(EmailValidator) that has list of validators(RegexValidator, MXValidator…) and it validates email through that validators.
RegexValidator, for example, has its own validators for each provider. If it recognizes that this is gmail, so it check if it match specific pattern, if it is mygmail, so it checks if it match mygmail’s pattern otherwize it return true.
MXValidator will validates something else.

What is the correct design pattern to implement this?

public interface IValidator
{
   bool Validate(string email);
}
public class RegexValidator : IValidator
    {
        private const string EMAIL_REGEX = @"\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b";
        public bool Validate(string email)
        {
            var regex = new Regex(EMAIL_REGEX);
            var isEmailFormat regex.IsMatch(email);
            if(isEmailFormat)
            {
                 //here it should recognize the provider and check if it match the provider's pattern
            }

            return true;
        }
    }
  • 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-03T02:12:54+00:00Added an answer on June 3, 2026 at 2:12 am

    Chain of Responsibility.

    As soon as one validator finds invalid pattern, returns false. You pass an ordered list of validators.

    bool ValidateEmail(string email, IEnumerable<IValidator> validators, ref errorMessage)
    {
        return !validators.Any(v => !v.Validate(email, ref errorMessage);
    }
    

    Assuming

    interface IValidator
    {
        bool Validate(object value, ref errorMessage);
    }
    

    UPDATE

    I see this implemented as another validator:

    public class EmailDomainValidator : IValidator
    {
    
       public EmailDomainValidator(string domain)
       {
          _domain = domain;
       }
    
       ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that validates the email address and I want to be
I have a regex that I am using to validate email addresses. I like
I have a large list of users that registered through a website without any
I have a php form that gets validated through javascript. I would like to
For my app, I have different signup entry points that validate things differently. So
I have a form that validates using jquery. The form's id is contact and
I have a form that validates using the jQuery plugin: Validation, v1.9.0. The validation
EDIT: Solution...email is a function within Validate which is a class so you need
I have a student that has many courses. In the student#update action and form,
I have to validate using regex decimal number between 00.00 to 35.35 with following

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.