Created
April 19, 2017 20:53
-
-
Save drmcarvalho/9071162c8796a46ec079cee9abaf361c to your computer and use it in GitHub Desktop.
Validar e-mail.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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