Created
August 2, 2017 07:09
-
-
Save randhirraj3130/42854e56892e672e849e51f726352433 to your computer and use it in GitHub Desktop.
how to validate email in unity c#
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
step 1-import the following | |
using System.Text.RegularExpressions; | |
step 2- define | |
public const string MatchEmailPattern = | |
@"^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@" | |
+ @"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\." | |
+ @"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|" | |
+ @"([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})$"; | |
step 3-call the following function | |
public static bool validateEmail (string email) | |
{ | |
if (email != null) | |
return Regex.IsMatch (email, MatchEmailPattern); | |
else | |
return false; | |
} |
working Well
Thanks!!
This definitely works for the most common email address not for the valid and STRANGE cases, any ways, who uses something like "[email protected]" (valid email address)? haha.
some others to test: https://en.wikipedia.org/wiki/Email_address
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
not work with email that host has a number prefix