Skip to content

Instantly share code, notes, and snippets.

@randhirraj3130
Created August 2, 2017 07:09
Show Gist options
  • Save randhirraj3130/42854e56892e672e849e51f726352433 to your computer and use it in GitHub Desktop.
Save randhirraj3130/42854e56892e672e849e51f726352433 to your computer and use it in GitHub Desktop.
how to validate email in unity c#
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;
}
@marck0zz
Copy link

marck0zz commented Aug 1, 2021

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