This file contains hidden or 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
<?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:Validators="clr-namespace:XamarinFormValidation.Validators.Implementations" | |
xmlns:Behaviors="clr-namespace:XamarinFormValidation.Behaviors" | |
xmlns:local="clr-namespace:XamarinFormValidation" x:Class="XamarinFormValidation.MainPage"> | |
<StackLayout Padding="15"> | |
<Label>Enter the mobile number</Label> | |
<Entry> | |
<Entry.Behaviors> |
This file contains hidden or 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
... | |
namespace XamarinFormValidation.Behaviors | |
{ | |
public class ValidationBehavior : Behavior<View> | |
{ | |
... | |
public bool Validate() | |
{ | |
... | |
} |
This file contains hidden or 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
... | |
<Entry> | |
<Entry.Behaviors> | |
<Behaviors:ValidationBehavior Group="{x:Reference form}" PropertyName="Text"> | |
<Behaviors:ValidationBehavior.Validators> | |
<v:FormatValidator Format="^[0-9]{6}$" Message="Village Code must be 6 digit" /> | |
<v:RequiredValidator /> | |
</Behaviors:ValidationBehavior.Validators> | |
</Behaviors:ValidationBehavior> | |
</Entry.Behaviors> |
This file contains hidden or 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
... | |
namespace XamarinFormValidation.Behaviors | |
{ | |
public class ValidationBehavior : Behavior<View> | |
{ | |
... | |
public bool Validate() | |
{ | |
bool isValid = true; | |
string errorMessage = ""; |
This file contains hidden or 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
using Xamarin.Forms; | |
using System.Collections.ObjectModel; | |
using XamarinFormValidation.Validators.Contracts; | |
using XamarinFormValidation.Validators.Implementations; | |
using System.ComponentModel; | |
namespace XamarinFormValidation.Behaviors | |
{ | |
public class ValidationBehavior : Behavior<View> | |
{ |
This file contains hidden or 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
using Xamarin.Forms; | |
using XamarinFormValidation.Validators.Contracts; | |
namespace XamarinFormValidation.Validators.Implementations | |
{ | |
public class BasicErrorStyle: IErrorStyle | |
{ | |
public void ShowError(View view, string message) | |
{ | |
StackLayout layout = view.Parent as StackLayout; |
This file contains hidden or 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
using Xamarin.Forms; | |
namespace XamarinFormValidation.Validators.Contracts | |
{ | |
public interface IErrorStyle | |
{ | |
void ShowError(View view, string message); | |
void RemoveError(View view); | |
} | |
} |
This file contains hidden or 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
using System.Text.RegularExpressions; | |
using XamarinFormValidation.Validators.Contracts; | |
namespace XamarinFormValidation.Validators.Implementations | |
{ | |
public class FormatValidator: IValidator | |
{ | |
public string Message { get; set; } = "Invalid format"; | |
public string Format { get; set; } |
This file contains hidden or 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
using XamarinFormValidation.Validators.Contracts; | |
namespace XamarinFormValidation.Validators.Implementations | |
{ | |
public class RequiredValidator: IValidator | |
{ | |
public string Message { get; set; } = "This field is required"; | |
public bool Check(string value) | |
{ |
This file contains hidden or 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
namespace XamarinFormValidation.Validators.Contracts | |
{ | |
public interface IValidator | |
{ | |
string Message { get; set; } | |
bool Check(string value); | |
} | |
} |