Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Testing email address validation
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//Title of this code //Rextester.Program.Main is the entry point for your code. Don't change it. using System; using System.Collections.Generic; using System.Linq; using System.Globalization; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static bool IsValidEmail(string strIn) { bool invalid = false; if (String.IsNullOrEmpty(strIn)) return false; // Use IdnMapping class to convert Unicode domain names. strIn = System.Text.RegularExpressions.Regex.Replace(strIn, @"(@)(.+)$", DomainMapper); if (invalid) return false; // Return true if strIn is in valid e-mail format. return System.Text.RegularExpressions.Regex.IsMatch(strIn, @"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" + @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$", System.Text.RegularExpressions.RegexOptions.IgnoreCase); } private static string DomainMapper(Match match) { // IdnMapping class with default property values. IdnMapping idn = new IdnMapping(); string domainName = match.Groups[2].Value; try { domainName = idn.GetAscii(domainName); } catch (ArgumentException ex) { Console.WriteLine("Error occured:"+ex.Message); } catch(Exception ex2) { Console.WriteLine("Error occured:"+ex2.Message); } return match.Groups[1].Value + domainName; } public static void Main(string[] args) { Console.WriteLine(IsValidEmail("jorgelu00_@hotmail.com").ToString()); } } }
Show compiler warnings
[
+
]
Show input
Compilation time: 0.14 sec, absolute running time: 0.11 sec, cpu time: 0.09 sec, average memory usage: 16 Mb, average nr of threads: 4 (cached)
edit mode
|
history
|
discussion