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:
For Passwords:
You will need to make sure that all passwords meet the company's criteria.
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!!
Get Answers For Free
Most questions answered within 1 hours.