This code check if the email is a valid email-adress.
To use this you need: System.Text.RegularExpressions
using System;
using System.Text.RegularExpressions;
namespace Snippet2
{
class Program
{
static void Main(string[] args)
{
Console.Write("Please write your email-adress here: ");
string email = Console.ReadLine();
isEmailValid(email);
Console.WriteLine(isEmailValid(email));
Console.ReadLine();
}
//check if email is valid
public static bool isEmailValid(string email)
{
return Regex.IsMatch(email, @"^([0-9a-zA-Z]([-\.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$");
}
}
}
1 Kommentare zum Snippet