Skip to content

Instantly share code, notes, and snippets.

@drmcarvalho
Created April 19, 2017 20:53
Show Gist options
  • Save drmcarvalho/9071162c8796a46ec079cee9abaf361c to your computer and use it in GitHub Desktop.
Save drmcarvalho/9071162c8796a46ec079cee9abaf361c to your computer and use it in GitHub Desktop.
Validar e-mail.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace EmailValido
{
class Program
{
static void Main(string[] args)
{
Console.Write("Email: ");
string email = Console.ReadLine();
if (EhEmailValido(email))
Console.WriteLine("Valido");
else
Console.WriteLine("Invalido");
Console.ReadKey();
}
static bool EhEmailValido(string email)
{
return Regex.IsMatch(email, @"^(?("")("".+?""@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-zA-Z])@))" + @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,6}))$");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment