Email Verification In Android And UWP Using Xamarin.Forms

Introduction

 
Xamarin is a platform that allows us to create a multi-platform app for Android, Windows, or iOS through a single integrated development environment (IDE). And with Xamarin.Forms, the interface design for all three platforms can be accomplished within its XAML-based standard, native user-interface control.
Email Verification In Android and UWP Using Xamarin.Forms
 
Android Output 
 
Email Verification In Android and UWP Using Xamarin.Forms
 
Email Verification In Android and UWP Using Xamarin.Forms
 
UWP Output 
 
Email Verification In Android and UWP Using Xamarin.Forms
 
Email Verification In Android and UWP Using Xamarin.Forms
 
Let's start. 
 
Step 1
 
Open Visual Studio and go to New Project >> Installed >> Visual C# >> Cross-Platform.
 
Select the Cross-Platform app, then give your project a name and location.
 
Email Verification In Android and UWP Using Xamarin.Forms
 
Step 2 
 
Open Solution Explorer >> Project Name (Portable) >> App.xaml.cs >> double-click will open the design view of this page.
 
Email Verification In Android and UWP Using Xamarin.Forms
 
The code is given below.
 
Email Verification In Android and UWP Using Xamarin.Forms
 
C# Code 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5.   
  6. using Xamarin.Forms;  
  7.   
  8. namespace Email_Verification  
  9. {  
  10.     public partial class App : Application  
  11.     {  
  12.         public App()  
  13.         {  
  14.             InitializeComponent();  
  15.   
  16.             MainPage = new NavigationPage(new MainPage());  
  17.         }  
  18.   
  19.         protected override void OnStart()  
  20.         {  
  21.             // Handle when your app starts  
  22.         }  
  23.   
  24.         protected override void OnSleep()  
  25.         {  
  26.             // Handle when your app sleeps  
  27.         }  
  28.   
  29.         protected override void OnResume()  
  30.         {  
  31.             // Handle when your app resumes  
  32.         }  
  33.     }  
  34. }   
Step 3
 
Next, add an image to Solution Explorer >> Project Name.Android >> Resources >> Right-Click >> drawable >> Add > Existing Item. 
 
Email Verification In Android and UWP Using Xamarin.Forms
 
Next, a dialogue box will open. Choose image location and add images.
 
Email Verification In Android and UWP Using Xamarin.Forms
 
Step 4
 
Next, add an image to the Solution Explorer. Go to Project Name.Universal Windows Platform  >> Right-Click >>  Add > Existing Item. 
 
Email Verification In Android and UWP Using Xamarin.Forms
 
Next, a dialogue box will open. Choose image location and add images.
 
Email Verification In Android and UWP Using Xamarin.Forms
 
Step 5
 
The image is added successfully for Android and UWP.
 
Email Verification In Android and UWP Using Xamarin.Forms
Step 6 
 
Next, open Solution Explorer >> project Name (Portable) >> Right-Click >> Add >> New Item or Ctrl+Shift+A. 
 
Email Verification In Android and UWP Using Xamarin.Forms
 
A new dialogue box will open. Now, add the XAML page and give it a name. Click the "Add" button.
 
Email Verification In Android and UWP Using Xamarin.Forms
 
Step 7 
 
Open Solution Explorer >> Project Name >> MainPage.xaml. Open the design view of this page.
 
Email Verification In Android and UWP Using Xamarin.Forms
 
The code for this is given below.
 
Email Verification In Android and UWP Using Xamarin.Forms
 
Xaml Code 
  1. <?xml version="1.0" encoding="utf-8" ?>  
  2. <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"  
  3.              xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"  
  4.              xmlns:local="clr-namespace:Email_Verification"  
  5.              x:Class="Email_Verification.MainPage"  
  6.              BackgroundImage="Image.jpg">  
  7.     <ContentPage.Content>  
  8.         <StackLayout>  
  9.             <Button Text="Email Verification"  
  10.                     Clicked="Button_Clicked"/>  
  11.         </StackLayout>  
  12.     </ContentPage.Content>  
  13. </ContentPage>   
Step 8
 
Open Solution Explorer >> Project Name >> MainPage.xaml.cs. Open the design view of this page. 
 
Email Verification In Android and UWP Using Xamarin.Forms
 
The code is given below. 
 
Email Verification In Android and UWP Using Xamarin.Forms
 
C# Code 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6. using Xamarin.Forms;  
  7.   
  8. namespace Email_Verification  
  9. {  
  10.     public partial class MainPage : ContentPage  
  11.     {  
  12.         public MainPage()  
  13.         {  
  14.             InitializeComponent();  
  15.         }  
  16.   
  17.         async private void Button_Clicked(object sender, EventArgs e)  
  18.         {  
  19.             await Navigation.PushAsync(new Page1());  
  20.         }  
  21.     }  
  22. }   
Step 9
 
Open Solution Explorer >> Project Name >> Page1.xaml. Open the design view of this page. 
 
Email Verification In Android and UWP Using Xamarin.Forms
 
The code is given below.
 
Email Verification In Android and UWP Using Xamarin.Forms
 
Xaml Code 
  1. <?xml version="1.0" encoding="utf-8" ?>  
  2. <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"  
  3.              xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"  
  4.              x:Class="Email_Verification.Page1">  
  5.     <ContentPage.Content>  
  6.         <StackLayout VerticalOptions="Center" HorizontalOptions="Center">  
  7.   
  8.             <Entry x:Name="EntryEmail" Placeholder="Enter The Email"/>  
  9.             <Label x:Name="LabelError" TextColor="Red"/>  
  10.             <Button Text="Validate" Clicked="Validar"/>  
  11.         </StackLayout>  
  12.     </ContentPage.Content>  
  13. </ContentPage>   
Step 10
 
Open Solution Explorer >> Project Name >> Page1.xaml.cs. Open the design view of this page.
 
Email Verification In Android and UWP Using Xamarin.Forms
 
The code is given below.
 
Email Verification In Android and UWP Using Xamarin.Forms
 
C# Code 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Text.RegularExpressions;  
  6. using System.Threading.Tasks;  
  7.   
  8. using Xamarin.Forms;  
  9. using Xamarin.Forms.Xaml;  
  10.   
  11. namespace Email_Verification  
  12. {  
  13.     [XamlCompilation(XamlCompilationOptions.Compile)]  
  14.     public partial class Page1 : ContentPage  
  15.     {  
  16.         public Page1()  
  17.         {  
  18.             InitializeComponent();  
  19.         }  
  20.   
  21.         public void Validar(Object sender, EventArgs e)  
  22.         {  
  23.             var email = EntryEmail.Text;  
  24.             var emailPattern = "^([\\w\\.\\-]+)@([\\w\\-]+)((\\.(\\w){2,3})+)$";  
  25.   
  26.             if (!String.IsNullOrWhiteSpace(email) && !(Regex.IsMatch(email, emailPattern)))  
  27.             {  
  28.                 LabelError.Text = "EmailVerification Failed";  
  29.             }  
  30.             else  
  31.             {  
  32.                 LabelError.Text = "Email Verification Success";  
  33.             }  
  34.         }  
  35.     }  
  36. }  
Step 11
 
Next, select the "Build and deploy" option followed by selecting from the list of Android Emulator or simulator. You can choose any API (Application program Interface) Level Emulator or simulator to run it. 
 
Output  
 
After a few seconds, you will see your app working.
 
Android Output 
 
You can choose the Android Platform.
 
Email Verification In Android and UWP Using Xamarin.Forms
 
Enter the email and click the Validate button. The result is displayed. 
 
Email Verification In Android and UWP Using Xamarin.Forms
 
Enter the Email and click the validate button. The result is displayed. 
 
Email Verification In Android and UWP Using Xamarin.Forms
 
UWP Output 
 
Similarly, you can choose UWP.
 
Email Verification In Android and UWP Using Xamarin.Forms
 
Enter the email and click the Validate button. The result is displayed.
 
Email Verification In Android and UWP Using Xamarin.Forms
 
Enter the email and click the Validate button. The result is displayed.
 
Email Verification In Android and UWP Using Xamarin.Forms
 
Finally, we have successfully created our desired Xamarin.Forms application.
 

Conclusion 

 
I hope you have learned about email verification in Android and UWP using Xamarin.Forms with Visual Studio and C#.


Similar Articles