what is the coding of email address validation using C# in xamarin.android visual studio 2015 and also tell me if any name space is requried? please tell me all the imp step as well as coding for email address validation in edittext. i am new in android.xamarin.. guys please help me
Asked
Active
Viewed 6,213 times
1 Answers
6
You can use Regex for email validation.
First add following using statement
using System.Text.RegularExpressions;
And after that use following helper method for validation:
Regex EmailRegex = new Regex (@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
public bool ValidateEmail(string email)
{
if (string.IsNullOrWhiteSpace(email))
return false;
return EmailRegex.IsMatch(email);
}
Option 2:
Xamarin.Android
has a helper method for email validation you also use that:
Android.Util.Patterns.EmailAddress.Matcher(email).Matches();

Adnan Umer
- 3,669
- 2
- 18
- 38
-
sir Thankyou for your rep .but when i tried this code give me a list of error they are as follow: 1` The modifier 'readonly' is not valid for this item App12 2, The type or namespace name 'Regex' could not be found (are you missing a using directive or an assembly reference?) 3,The type or namespace name 'Regex' could not be found (are you missing a using directive or an assembly reference?)` – shumeza Aug 29 '16 at 06:18
-
Remove `readonly` modifier and add following using statement on top of file: `using System.Text.RegularExpressions;` – Adnan Umer Aug 29 '16 at 06:19
-
sir, i created a new class for this function .can u please tell me how we can call this function to my SignUpactivity in `if()` condition – shumeza Aug 29 '16 at 06:34
-
If you have added that in new class first you need to mark that function `ValidateEmail` & `EmailRegex` as `static`. After that you can use that as `YourClass.ValidateEmail(someTextField.Text)` – Adnan Umer Aug 29 '16 at 06:36
-
id this coding `{if (mtxtEmial.Text == emailaddressValidation.ValidateEmail(string email)){}` is correct? – shumeza Aug 29 '16 at 06:36
-
no. call this way `if (emailaddressValidation.ValidateEmail(mtxtEmial.Text)) { }` – Adnan Umer Aug 29 '16 at 06:37
-
sir can u please tell me Regex valitadion function for password ,phone no, address and name in an edittext – shumeza Aug 29 '16 at 07:04
-
Good basis, but not entirely correct (e.g. the local part of the email address nowadays also permits various (other) non-alphanumeric characters like `+`, `$`, `%` and the likes). – Levite Dec 10 '20 at 13:00