using System.Text.RegularExpressions;
public static void Main()
string strPersonalEmailID;
string strPersonalEmailPassword;
Console.WriteLine("Enter your Email Id:");
strEmailID = Console.ReadLine();
Console.WriteLine("Enter your Email Password:");
strEmailPassword = Console.ReadLine();
Console.WriteLine("Enter your personal Email Id:");
strPersonalEmailID = Console.ReadLine();
Console.WriteLine("Enter your personal Email Password:");
strPersonalEmailPassword = Console.ReadLine();
PersonalEmailAccount objValidateEmailAccount = new PersonalEmailAccount();
Console.WriteLine("\nResult :");
if (objValidateEmailAccount.ValidatePassword(strEmailID, strEmailPassword, out strError))
Console.WriteLine("Your Email and Password are correct");
Console.WriteLine(strError);
if(objValidateEmailAccount.ValidatePersonalEmailAccount(strPersonalEmailID, strPersonalEmailPassword, out strError))
Console.WriteLine("Your Personal Email and Password are correct");
Console.WriteLine(strError);
public class ValidateEmailAccount
public bool ValidatePassword(string Email, string Password, out string ErrorMessage)
ErrorMessage = string.Empty;
if (string.IsNullOrWhiteSpace(Email))
throw new Exception("Email should not be empty");
if (string.IsNullOrWhiteSpace(Password))
throw new Exception("Password should not be empty");
var hasEmail= new Regex(@"\w+([-+.]\w+)*@(yahoo\.com|gmail\.com)");
var hasNumber = new Regex(@"[0-9]{1,1}");
var hasUpperChar = new Regex(@"[A-Z]{1,1}");
var hasMiniChars = new Regex(@".{8,8}");
var hasLowerChar = new Regex(@"[a-z]{5,5}");
var hasSymbols = new Regex(@"[!@#$%^&*()_+=\[{\]};:<>|./?,-]{1,1}");
if (!hasEmail.IsMatch(Email))
ErrorMessage = "Email id account should be either gmail.com or yahoo.com";
if (!hasLowerChar.IsMatch(Password))
ErrorMessage = "Password should contain one lower case letter.";
else if (!hasUpperChar.IsMatch(Password))
ErrorMessage = "Password should contain one upper case letter.";
else if (!hasMiniChars.IsMatch(Password))
ErrorMessage = "Password should contain 8 characters.";
else if (!hasNumber.IsMatch(Password))
ErrorMessage = "Password should contain one numeric value.";
else if (!hasSymbols.IsMatch(Password))
ErrorMessage = "Password should contain one special case character.";
public class PersonalEmailAccount : ValidateEmailAccount
public bool ValidatePersonalEmailAccount(string Email, string Password, out string ErrorMessage)
ErrorMessage = string.Empty;
if (string.IsNullOrWhiteSpace(Email))
throw new Exception("Personal Email ID should not be empty");
if (string.IsNullOrWhiteSpace(Password))
throw new Exception("Personal Password should not be empty");
var hasChars = new Regex(@".{8,10}");
var hasEmail = new Regex(@"\w+([-+.]\w+)*@(yahoo\.com|gmail\.com)");
if (!hasEmail.IsMatch(Email))
ErrorMessage = "Personal Email id account should be either gmail.com or yahoo.com";
if (!hasChars.IsMatch(Password))
ErrorMessage = "personal Email Password should not contain lessthan 8 characters and greater than 10 characters.";