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.
Android Output
UWP Output
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.
Step 2
Open Solution Explorer >> Project Name (Portable) >> App.xaml.cs >> double-click will open the design view of this page.
The code is given below.
C# Code
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
-
- using Xamarin.Forms;
-
- namespace Email_Verification
- {
- public partial class App : Application
- {
- public App()
- {
- InitializeComponent();
-
- MainPage = new NavigationPage(new MainPage());
- }
-
- protected override void OnStart()
- {
-
- }
-
- protected override void OnSleep()
- {
-
- }
-
- protected override void OnResume()
- {
-
- }
- }
- }
Step 3
Next, add an image to Solution Explorer >> Project Name.Android >> Resources >> Right-Click >> drawable >> Add > Existing Item.
Next, a dialogue box will open. Choose image location and add images.
Step 4
Next, add an image to the Solution Explorer. Go to Project Name.Universal Windows Platform >> Right-Click >> Add > Existing Item.
Next, a dialogue box will open. Choose image location and add images.
Step 5
The image is added successfully for Android and UWP.
Step 6
Next, open Solution Explorer >> project Name (Portable) >> Right-Click >> Add >> New Item or Ctrl+Shift+A.
A new dialogue box will open. Now, add the XAML page and give it a name. Click the "Add" button.
Step 7
Open Solution Explorer >> Project Name >> MainPage.xaml. Open the design view of this page.
The code for this is given below.
Xaml Code
- <?xml version="1.0" encoding="utf-8" ?>
- <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
- xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
- xmlns:local="clr-namespace:Email_Verification"
- x:Class="Email_Verification.MainPage"
- BackgroundImage="Image.jpg">
- <ContentPage.Content>
- <StackLayout>
- <Button Text="Email Verification"
- Clicked="Button_Clicked"/>
- </StackLayout>
- </ContentPage.Content>
- </ContentPage>
Step 8
Open Solution Explorer >> Project Name >> MainPage.xaml.cs. Open the design view of this page.
The code is given below.
C# Code
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Xamarin.Forms;
-
- namespace Email_Verification
- {
- public partial class MainPage : ContentPage
- {
- public MainPage()
- {
- InitializeComponent();
- }
-
- async private void Button_Clicked(object sender, EventArgs e)
- {
- await Navigation.PushAsync(new Page1());
- }
- }
- }
Step 9
Open Solution Explorer >> Project Name >> Page1.xaml. Open the design view of this page.
The code is given below.
Xaml Code
- <?xml version="1.0" encoding="utf-8" ?>
- <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
- xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
- x:Class="Email_Verification.Page1">
- <ContentPage.Content>
- <StackLayout VerticalOptions="Center" HorizontalOptions="Center">
-
- <Entry x:Name="EntryEmail" Placeholder="Enter The Email"/>
- <Label x:Name="LabelError" TextColor="Red"/>
- <Button Text="Validate" Clicked="Validar"/>
- </StackLayout>
- </ContentPage.Content>
- </ContentPage>
Step 10
Open Solution Explorer >> Project Name >> Page1.xaml.cs. Open the design view of this page.
The code is given below.
C# Code
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
-
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
-
- namespace Email_Verification
- {
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class Page1 : ContentPage
- {
- public Page1()
- {
- InitializeComponent();
- }
-
- public void Validar(Object sender, EventArgs e)
- {
- var email = EntryEmail.Text;
- var emailPattern = "^([\\w\\.\\-]+)@([\\w\\-]+)((\\.(\\w){2,3})+)$";
-
- if (!String.IsNullOrWhiteSpace(email) && !(Regex.IsMatch(email, emailPattern)))
- {
- LabelError.Text = "EmailVerification Failed";
- }
- else
- {
- LabelError.Text = "Email Verification Success";
- }
- }
- }
- }
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.
Enter the email and click the Validate button. The result is displayed.
Enter the Email and click the validate button. The result is displayed.
Similarly, you can choose UWP.
Enter the email and click the Validate button. The result is displayed.
Enter the email and click the Validate button. The result is displayed.
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#.