Question

This question has been answered before. Please provide a new code and screenshot of output. Thank...

This question has been answered before. Please provide a new code and screenshot of output. Thank you!

Create a C# program that accepts an e-mail address and a password as input and validates it using the following methods (Please note, this is not all-inclusive.):

For the E-Mail Address:

Best practice for validating an email address:

  • It is case sensitive in the local portion of the address (left of the rightmost @ character)
  • Has non-alphanumeric characters in the local-part (including + and @)
  • Has zero or more labels
  • Check for presence of at least one @ symbol in the address

For Passwords:

You will need to make sure that all passwords meet the company's criteria.

  • Data Type validation
  • Format validation
  • That the password has at least 10 characters, 1 upper case, 1 lower case, 1 number between 1 and 20.
  • That it doesn't use semicolons or quotes.

Homework Answers

Answer #1

HI

Please find the code below to validate email and password respectively

I made a console application to demonstrate the validation process

// program class
class Program
{
// main function
static void Main(string[] args)
{
Console.WriteLine("Please enter Email");
string Email = Console.ReadLine();
Console.WriteLine("Please enter Password");
string password = Console.ReadLine();

// use the below rejex which to make sure the email is valid
string emailRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
@"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
@".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
//create email rejex using above string
Regex email = new Regex(emailRegex);
// check whether email is valid or not
if (!email.IsMatch(Email))
Console.WriteLine("Email is not Correct");

// check for password length
if (password.Length < 10)
Console.WriteLine("Please use a valid password");

// use below rejex fo rvalidating password
string passwordRejet = "^[a-zA-Z0-9]*$";
Regex pass = new Regex(passwordRejet);
// check for password
if (!pass.IsMatch(password))
Console.WriteLine("Please use a valid password");

}

}

OUTPUT:

Thanks

Hope it helps!!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT