├── .gitattributes ├── .github ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── Assets ├── Plugin.ValidationRules test.gif ├── icon.png ├── icon.svg └── validation rules xamarin - @luismatosluna.pdf ├── LICENSE ├── README.md ├── samples ├── Maui │ └── ValidationRulesTest │ │ ├── ValidationRulesTest.sln │ │ └── ValidationRulesTest │ │ ├── App.xaml │ │ ├── App.xaml.cs │ │ ├── Behaviors │ │ ├── BehaviorBase.cs │ │ └── EventToCommandBehavior.cs │ │ ├── MauiProgram.cs │ │ ├── Models │ │ ├── User.cs │ │ ├── UserValidator.cs │ │ └── UserValidator2.cs │ │ ├── Platforms │ │ ├── Android │ │ │ ├── AndroidManifest.xml │ │ │ ├── MainActivity.cs │ │ │ ├── MainApplication.cs │ │ │ └── Resources │ │ │ │ └── values │ │ │ │ └── colors.xml │ │ ├── MacCatalyst │ │ │ ├── AppDelegate.cs │ │ │ ├── Info.plist │ │ │ └── Program.cs │ │ ├── Windows │ │ │ ├── App.xaml │ │ │ ├── App.xaml.cs │ │ │ ├── Package.appxmanifest │ │ │ └── app.manifest │ │ └── iOS │ │ │ ├── AppDelegate.cs │ │ │ ├── Info.plist │ │ │ └── Program.cs │ │ ├── Properties │ │ └── launchSettings.json │ │ ├── Resources │ │ ├── Fonts │ │ │ └── OpenSans-Regular.ttf │ │ ├── Images │ │ │ └── dotnet_bot.svg │ │ ├── appicon.svg │ │ └── appiconfg.svg │ │ ├── ValidationRulesTest.csproj │ │ ├── Validations │ │ ├── EmailRule.cs │ │ ├── IsNotNullOrEmptyRule.cs │ │ ├── PasswordRule.cs │ │ └── UserRule.cs │ │ ├── ViewModels │ │ ├── Example1ViewModel.cs │ │ ├── Example2ViewModel.cs │ │ ├── Example3ViewModel.cs │ │ ├── Example4ViewModel.cs │ │ ├── Example5ViewModel.cs │ │ ├── Example6ViewModel.cs │ │ ├── Example7ViewModel.cs │ │ └── Example8ViewModel.cs │ │ └── Views │ │ ├── Example1.xaml │ │ ├── Example1.xaml.cs │ │ ├── Example2.xaml │ │ ├── Example2.xaml.cs │ │ ├── Example3.xaml │ │ ├── Example3.xaml.cs │ │ ├── Example4.xaml │ │ ├── Example4.xaml.cs │ │ ├── Example5.xaml │ │ ├── Example5.xaml.cs │ │ ├── Example6.xaml │ │ ├── Example6.xaml.cs │ │ ├── Example7.xaml │ │ ├── Example7.xaml.cs │ │ ├── Example8.xaml │ │ ├── Example8.xaml.cs │ │ ├── Examples.xaml │ │ └── Examples.xaml.cs └── Xamarin.Forms │ ├── ValidationRulesTest.sln │ └── ValidationRulesTest │ ├── ValidationRulesTest.Android │ ├── Assets │ │ └── AboutAssets.txt │ ├── MainActivity.cs │ ├── Properties │ │ ├── AndroidManifest.xml │ │ └── AssemblyInfo.cs │ ├── Resources │ │ ├── AboutResources.txt │ │ ├── Resource.designer.cs │ │ ├── layout │ │ │ ├── Tabbar.axml │ │ │ └── Toolbar.axml │ │ ├── mipmap-anydpi-v26 │ │ │ ├── icon.xml │ │ │ └── icon_round.xml │ │ ├── mipmap-hdpi │ │ │ ├── Icon.png │ │ │ └── launcher_foreground.png │ │ ├── mipmap-mdpi │ │ │ ├── icon.png │ │ │ └── launcher_foreground.png │ │ ├── mipmap-xhdpi │ │ │ ├── Icon.png │ │ │ └── launcher_foreground.png │ │ ├── mipmap-xxhdpi │ │ │ ├── Icon.png │ │ │ └── launcher_foreground.png │ │ ├── mipmap-xxxhdpi │ │ │ ├── Icon.png │ │ │ └── launcher_foreground.png │ │ └── values │ │ │ ├── colors.xml │ │ │ └── styles.xml │ └── ValidationRulesTest.Android.csproj │ ├── ValidationRulesTest.iOS │ ├── AppDelegate.cs │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ ├── Contents.json │ │ │ ├── Icon1024.png │ │ │ ├── Icon120.png │ │ │ ├── Icon152.png │ │ │ ├── Icon167.png │ │ │ ├── Icon180.png │ │ │ ├── Icon20.png │ │ │ ├── Icon29.png │ │ │ ├── Icon40.png │ │ │ ├── Icon58.png │ │ │ ├── Icon60.png │ │ │ ├── Icon76.png │ │ │ ├── Icon80.png │ │ │ └── Icon87.png │ ├── Entitlements.plist │ ├── Info.plist │ ├── Main.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Resources │ │ ├── Default-568h@2x.png │ │ ├── Default-Portrait.png │ │ ├── Default-Portrait@2x.png │ │ ├── Default.png │ │ ├── Default@2x.png │ │ └── LaunchScreen.storyboard │ └── ValidationRulesTest.iOS.csproj │ └── ValidationRulesTest │ ├── App.xaml │ ├── App.xaml.cs │ ├── Behaviors │ ├── BehaviorBase.cs │ └── EventToCommandBehavior.cs │ ├── Models │ ├── User.cs │ ├── UserValidator.cs │ └── UserValidator2.cs │ ├── ValidationRulesTest.csproj │ ├── Validations │ ├── EmailRule.cs │ ├── IsNotNullOrEmptyRule.cs │ ├── PasswordRule.cs │ └── UserRule.cs │ ├── ViewModels │ ├── Example1ViewModel.cs │ ├── Example2ViewModel.cs │ ├── Example3ViewModel.cs │ ├── Example4ViewModel.cs │ ├── Example5ViewModel.cs │ ├── Example6ViewModel.cs │ ├── Example7ViewModel.cs │ └── Example8ViewModel.cs │ └── Views │ ├── Example1.xaml │ ├── Example1.xaml.cs │ ├── Example2.xaml │ ├── Example2.xaml.cs │ ├── Example3.xaml │ ├── Example3.xaml.cs │ ├── Example4.xaml │ ├── Example4.xaml.cs │ ├── Example5.xaml │ ├── Example5.xaml.cs │ ├── Example6.xaml │ ├── Example6.xaml.cs │ ├── Example7.xaml │ ├── Example7.xaml.cs │ ├── Example8.xaml │ ├── Example8.xaml.cs │ ├── Examples.xaml │ └── Examples.xaml.cs └── src └── ValidationRules ├── Extensions ├── ExtendedPropertyChanged.cs ├── Extensions.cs ├── RelayCommand.cs ├── Validator.cs ├── ValidatorList.cs └── ValueChangedEventArgs.cs ├── Formatters ├── BoolNegationFormatter.cs ├── MaskFormatter.cs ├── StringCaseFormatter.cs └── StringNumericFormatter.cs ├── Interfaces ├── IMapperValidator.cs ├── IValidationRule.cs ├── IValidity.cs └── IValueFormatter.cs ├── Plugin.ValidationRules.csproj ├── Plugin.ValidationRules.nuspec ├── Rules ├── CreditCardRule.cs ├── EmailRule.cs ├── EmptyRule.cs ├── EnumRule.cs ├── EqualRule.cs ├── FunctionRule.cs ├── GreaterThanOrEqualRule.cs ├── GreaterThanRule.cs ├── InclusiveBetweenRule.cs ├── LengthRule.cs ├── LessThanOrEqualRule.cs ├── LessThanRule.cs ├── NotEmptyRule.cs ├── NotEqualRule.cs ├── NotNullRule.cs ├── NullRule.cs ├── RegularExpressionRule.cs └── WhenRule.cs ├── Validatable.cs ├── ValidatableList.cs ├── ValidationUnit.cs └── Validator.cs /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | # Explicitly declare text files we want to always be normalized and converted 16 | # to native line endings on checkout. 17 | *.cs text 18 | 19 | # Declare files that will always have CRLF line endings on checkout. 20 | *.sln text eol=crlf 21 | 22 | # Ignore files 23 | *.css linguist-detectable=false 24 | *.js linguist-detectable=false 25 | *.html linguist-detectable=false 26 | 27 | ############################################################################### 28 | # Set the merge driver for project and solution files 29 | # 30 | # Merging from the command prompt will add diff markers to the files if there 31 | # are conflicts (Merging from VS is not affected by the settings below, in VS 32 | # the diff markers are never inserted). Diff markers may cause the following 33 | # file extensions to fail to load in VS. An alternative would be to treat 34 | # these files as binary and thus will always conflict and require user 35 | # intervention with every merge. To do so, just uncomment the entries below 36 | ############################################################################### 37 | #*.sln merge=binary 38 | #*.csproj merge=binary 39 | #*.vbproj merge=binary 40 | #*.vcxproj merge=binary 41 | #*.vcproj merge=binary 42 | #*.dbproj merge=binary 43 | #*.fsproj merge=binary 44 | #*.lsproj merge=binary 45 | #*.wixproj merge=binary 46 | #*.modelproj merge=binary 47 | #*.sqlproj merge=binary 48 | #*.wwaproj merge=binary 49 | 50 | ############################################################################### 51 | # behavior for image files 52 | # 53 | # image files are treated as binary by default. 54 | ############################################################################### 55 | *.jpg binary 56 | *.png binary 57 | *.gif binary 58 | *.jpeg binary 59 | 60 | ############################################################################### 61 | # diff behavior for common document formats 62 | # 63 | # Convert binary document formats to text before diffing them. This feature 64 | # is only available from the command line. Turn it on by uncommenting the 65 | # entries below. 66 | ############################################################################### 67 | #*.doc diff=astextplain 68 | #*.DOC diff=astextplain 69 | #*.docx diff=astextplain 70 | #*.DOCX diff=astextplain 71 | #*.dot diff=astextplain 72 | #*.DOT diff=astextplain 73 | #*.pdf diff=astextplain 74 | #*.PDF diff=astextplain 75 | #*.rtf diff=astextplain 76 | #*.RTF diff=astextplain 77 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | **Failure to fill out this information will result in this issue being closed.** 2 | 3 | If you are creating an issue for a BUG please fill out this information. If you are asking a question or requesting a feature you can delete the sections below. 4 | 5 | If you post a full stack trace in a bug it will be closed, please post it to http://gist.github.com and then post the link here. 6 | 7 | ## Bug Information 8 | 9 | Version Number of Plugin: 10 | Device Tested On: 11 | Simulator Tested On: 12 | Version of VS: 13 | Version of Xamarin: 14 | Versions of other things you are using: 15 | 16 | ### Steps to reproduce the Behavior 17 | 18 | ### Expected Behavior 19 | 20 | ### Actual Behavior 21 | 22 | ### Code snippet 23 | 24 | ### Screenshots 25 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Please take a moment to fill out the following: 2 | 3 | Fixes issue # 4 | 5 | Changes Proposed in this pull request: 6 | - 7 | - 8 | - 9 | 10 | 11 | ### PR Checklist ### 12 | 13 | - [ ] Has tests (if omitted, state reason in description) 14 | - [ ] Rebased on top of master at time of PR 15 | - [ ] Consolidate commits as makes sense 16 | -------------------------------------------------------------------------------- /Assets/Plugin.ValidationRules test.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luismts/ValidationRulesPlugin/be8e76caa78f30643c51b7dba50379e95c06837f/Assets/Plugin.ValidationRules test.gif -------------------------------------------------------------------------------- /Assets/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luismts/ValidationRulesPlugin/be8e76caa78f30643c51b7dba50379e95c06837f/Assets/icon.png -------------------------------------------------------------------------------- /Assets/icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 8 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Assets/validation rules xamarin - @luismatosluna.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luismts/ValidationRulesPlugin/be8e76caa78f30643c51b7dba50379e95c06837f/Assets/validation rules xamarin - @luismatosluna.pdf -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Luis Matos 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.31611.283 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ValidationRulesTest", "ValidationRulesTest\ValidationRulesTest.csproj", "{3D37E29F-042E-4E34-B363-DBBE702383DE}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Plugin.ValidationRules", "..\..\..\src\ValidationRules\Plugin.ValidationRules.csproj", "{74CB3C79-59A7-4AAA-A94F-EDA9D278847E}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {3D37E29F-042E-4E34-B363-DBBE702383DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {3D37E29F-042E-4E34-B363-DBBE702383DE}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {3D37E29F-042E-4E34-B363-DBBE702383DE}.Debug|Any CPU.Deploy.0 = Debug|Any CPU 19 | {3D37E29F-042E-4E34-B363-DBBE702383DE}.Release|Any CPU.ActiveCfg = Release|Any CPU 20 | {3D37E29F-042E-4E34-B363-DBBE702383DE}.Release|Any CPU.Build.0 = Release|Any CPU 21 | {3D37E29F-042E-4E34-B363-DBBE702383DE}.Release|Any CPU.Deploy.0 = Release|Any CPU 22 | {74CB3C79-59A7-4AAA-A94F-EDA9D278847E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {74CB3C79-59A7-4AAA-A94F-EDA9D278847E}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {74CB3C79-59A7-4AAA-A94F-EDA9D278847E}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {74CB3C79-59A7-4AAA-A94F-EDA9D278847E}.Release|Any CPU.Build.0 = Release|Any CPU 26 | EndGlobalSection 27 | GlobalSection(SolutionProperties) = preSolution 28 | HideSolutionNode = FALSE 29 | EndGlobalSection 30 | GlobalSection(ExtensibilityGlobals) = postSolution 31 | SolutionGuid = {61F7FB11-1E47-470C-91E2-47F8143E1572} 32 | EndGlobalSection 33 | EndGlobal 34 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/App.xaml: -------------------------------------------------------------------------------- 1 |  7 | 8 | 9 | 10 | #512bdf 11 | White 12 | 13 | 17 | 18 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using ValidationRulesTest.Views; 2 | 3 | namespace ValidationRulesTest; 4 | 5 | public partial class App : Application 6 | { 7 | public App() 8 | { 9 | InitializeComponent(); 10 | 11 | MainPage = new NavigationPage(new Examples()); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/Behaviors/BehaviorBase.cs: -------------------------------------------------------------------------------- 1 | namespace ValidationRulesTest.Behaviors 2 | { 3 | /// 4 | /// Base class that extends on Xamarin Forms Behaviors. 5 | /// 6 | /// 7 | public class BehaviorBase : Behavior where T : BindableObject 8 | { 9 | /// 10 | /// The Object associated with the Behavior 11 | /// 12 | public T AssociatedObject { get; private set; } 13 | 14 | /// 15 | protected override void OnAttachedTo(T bindable) 16 | { 17 | base.OnAttachedTo(bindable); 18 | AssociatedObject = bindable; 19 | 20 | if (bindable.BindingContext != null) 21 | { 22 | BindingContext = bindable.BindingContext; 23 | } 24 | 25 | bindable.BindingContextChanged += OnBindingContextChanged; 26 | } 27 | 28 | /// 29 | protected override void OnDetachingFrom(T bindable) 30 | { 31 | base.OnDetachingFrom(bindable); 32 | bindable.BindingContextChanged -= OnBindingContextChanged; 33 | AssociatedObject = null; 34 | } 35 | 36 | void OnBindingContextChanged(object sender, EventArgs e) 37 | { 38 | OnBindingContextChanged(); 39 | } 40 | 41 | /// 42 | protected override void OnBindingContextChanged() 43 | { 44 | base.OnBindingContextChanged(); 45 | BindingContext = AssociatedObject.BindingContext; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/MauiProgram.cs: -------------------------------------------------------------------------------- 1 | namespace ValidationRulesTest; 2 | 3 | public static class MauiProgram 4 | { 5 | public static MauiApp CreateMauiApp() 6 | { 7 | var builder = MauiApp.CreateBuilder(); 8 | builder 9 | .UseMauiApp() 10 | .ConfigureFonts(fonts => 11 | { 12 | fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); 13 | }); 14 | 15 | return builder.Build(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/Models/User.cs: -------------------------------------------------------------------------------- 1 | namespace ValidationRulesTest.Models 2 | { 3 | public class User 4 | { 5 | public string LastName { get; set; } 6 | public string Name { get; set; } 7 | public string Email { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/Models/UserValidator.cs: -------------------------------------------------------------------------------- 1 | using Plugin.ValidationRules; 2 | using Plugin.ValidationRules.Interfaces; 3 | using ValidationRulesTest.Validations; 4 | 5 | namespace ValidationRulesTest.Models 6 | { 7 | public class UserValidator : IMapperValidator 8 | { 9 | ValidationUnit _unit1; 10 | 11 | public UserValidator() 12 | { 13 | LastName = new Validatable(); 14 | Name = new Validatable(); 15 | Email = new Validatable(); 16 | 17 | _unit1 = new ValidationUnit(Name, LastName, Email); 18 | 19 | // Name validations 20 | Name.Validations.Add(new IsNotNullOrEmptyRule { ValidationMessage = "A name is required." }); 21 | 22 | //Lastname validations 23 | LastName.Validations.Add(new IsNotNullOrEmptyRule { ValidationMessage = "A lastname is required." }); 24 | 25 | //Email validations 26 | Email.Validations.Add(new IsNotNullOrEmptyRule { ValidationMessage = "A email is required." }); 27 | Email.Validations.Add(new EmailRule()); 28 | } 29 | 30 | public Validatable LastName { get; set; } 31 | public Validatable Name { get; set; } 32 | public Validatable Email { get; set; } 33 | 34 | public bool Validate() 35 | { 36 | // Your logic goes here 37 | return _unit1.Validate(); 38 | } 39 | 40 | public User Map() 41 | { 42 | // Simple Manual Mapper 43 | var manualMapperUser = new User 44 | { 45 | Name = this.Name.Value, 46 | LastName = this.LastName.Value, 47 | Email = this.Email.Value 48 | }; 49 | 50 | return manualMapperUser; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/Models/UserValidator2.cs: -------------------------------------------------------------------------------- 1 | using Plugin.ValidationRules; 2 | using Plugin.ValidationRules.Extensions; 3 | using ValidationRulesTest.Validations; 4 | 5 | namespace ValidationRulesTest.Models 6 | { 7 | public class UserValidator2 : Validator 8 | { 9 | public UserValidator2() 10 | { 11 | //Name validations 12 | Name = Build() 13 | .WithRule(new IsNotNullOrEmptyRule(), "A name is required."); 14 | 15 | //Lastname validations 16 | LastName = Build() 17 | .WithRule(new IsNotNullOrEmptyRule(), "A lastname is required."); 18 | 19 | //Email validations 20 | Email = Build() 21 | .IsRequired("A email is required.") 22 | .WithRule(new EmailRule()); 23 | 24 | InitUnit(); 25 | } 26 | 27 | public Validatable LastName { get; set; } 28 | public Validatable Name { get; set; } 29 | public Validatable Email { get; set; } 30 | 31 | //public override bool Validate() 32 | //{ 33 | // Your logic goes here 34 | // return _unit1.Validate(); 35 | //} 36 | 37 | public override User Map() 38 | { 39 | // Simple Manual Mapper 40 | var manualMapperUser = new User 41 | { 42 | Name = this.Name.Value, 43 | LastName = this.LastName.Value, 44 | Email = this.Email.Value 45 | }; 46 | 47 | return manualMapperUser; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/Platforms/Android/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/Platforms/Android/MainActivity.cs: -------------------------------------------------------------------------------- 1 | using Android.App; 2 | using Android.Content.PM; 3 | using Android.OS; 4 | 5 | namespace ValidationRulesTest; 6 | 7 | [Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)] 8 | public class MainActivity : MauiAppCompatActivity 9 | { 10 | protected override void OnCreate(Bundle savedInstanceState) 11 | { 12 | base.OnCreate(savedInstanceState); 13 | Platform.Init(this, savedInstanceState); 14 | } 15 | 16 | public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults) 17 | { 18 | Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults); 19 | 20 | base.OnRequestPermissionsResult(requestCode, permissions, grantResults); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/Platforms/Android/MainApplication.cs: -------------------------------------------------------------------------------- 1 | using Android.App; 2 | using Android.Runtime; 3 | 4 | namespace ValidationRulesTest; 5 | 6 | [Application] 7 | public class MainApplication : MauiApplication 8 | { 9 | public MainApplication(IntPtr handle, JniHandleOwnership ownership) 10 | : base(handle, ownership) 11 | { 12 | } 13 | 14 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); 15 | } 16 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/Platforms/Android/Resources/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #512BD4 4 | #2B0B98 5 | #2B0B98 6 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/Platforms/MacCatalyst/AppDelegate.cs: -------------------------------------------------------------------------------- 1 | using Foundation; 2 | 3 | namespace ValidationRulesTest; 4 | 5 | [Register("AppDelegate")] 6 | public class AppDelegate : MauiUIApplicationDelegate 7 | { 8 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); 9 | } 10 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/Platforms/MacCatalyst/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UIDeviceFamily 6 | 7 | 1 8 | 2 9 | 10 | UIRequiredDeviceCapabilities 11 | 12 | arm64 13 | 14 | UISupportedInterfaceOrientations 15 | 16 | UIInterfaceOrientationPortrait 17 | UIInterfaceOrientationLandscapeLeft 18 | UIInterfaceOrientationLandscapeRight 19 | 20 | UISupportedInterfaceOrientations~ipad 21 | 22 | UIInterfaceOrientationPortrait 23 | UIInterfaceOrientationPortraitUpsideDown 24 | UIInterfaceOrientationLandscapeLeft 25 | UIInterfaceOrientationLandscapeRight 26 | 27 | XSAppIconAssets 28 | Assets.xcassets/appicon.appiconset 29 | 30 | 31 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/Platforms/MacCatalyst/Program.cs: -------------------------------------------------------------------------------- 1 | using UIKit; 2 | 3 | namespace ValidationRulesTest; 4 | 5 | public class Program 6 | { 7 | // This is the main entry point of the application. 8 | static void Main(string[] args) 9 | { 10 | // if you want to use a different Application Delegate class from "AppDelegate" 11 | // you can specify it here. 12 | UIApplication.Main(args, null, typeof(AppDelegate)); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/Platforms/Windows/App.xaml: -------------------------------------------------------------------------------- 1 |  7 | 8 | 9 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/Platforms/Windows/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.UI.Xaml; 2 | 3 | // To learn more about WinUI, the WinUI project structure, 4 | // and more about our project templates, see: http://aka.ms/winui-project-info. 5 | 6 | namespace ValidationRulesTest.WinUI; 7 | 8 | /// 9 | /// Provides application-specific behavior to supplement the default Application class. 10 | /// 11 | public partial class App : MauiWinUIApplication 12 | { 13 | /// 14 | /// Initializes the singleton application object. This is the first line of authored code 15 | /// executed, and as such is the logical equivalent of main() or WinMain(). 16 | /// 17 | public App() 18 | { 19 | this.InitializeComponent(); 20 | } 21 | 22 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); 23 | 24 | protected override void OnLaunched(LaunchActivatedEventArgs args) 25 | { 26 | base.OnLaunched(args); 27 | 28 | Platform.OnLaunched(args); 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/Platforms/Windows/Package.appxmanifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 8 | 9 | 13 | 14 | 15 | ValidationRulesTest 16 | Microsoft 17 | Assets\appiconStoreLogo.png 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 33 | 39 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/Platforms/Windows/app.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 11 | true/PM 12 | PerMonitorV2, PerMonitor 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/Platforms/iOS/AppDelegate.cs: -------------------------------------------------------------------------------- 1 | using Foundation; 2 | 3 | namespace ValidationRulesTest; 4 | 5 | [Register("AppDelegate")] 6 | public class AppDelegate : MauiUIApplicationDelegate 7 | { 8 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); 9 | } 10 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/Platforms/iOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | LSRequiresIPhoneOS 6 | 7 | UIDeviceFamily 8 | 9 | 1 10 | 2 11 | 12 | UIRequiredDeviceCapabilities 13 | 14 | arm64 15 | 16 | UISupportedInterfaceOrientations 17 | 18 | UIInterfaceOrientationPortrait 19 | UIInterfaceOrientationLandscapeLeft 20 | UIInterfaceOrientationLandscapeRight 21 | 22 | UISupportedInterfaceOrientations~ipad 23 | 24 | UIInterfaceOrientationPortrait 25 | UIInterfaceOrientationPortraitUpsideDown 26 | UIInterfaceOrientationLandscapeLeft 27 | UIInterfaceOrientationLandscapeRight 28 | 29 | XSAppIconAssets 30 | Assets.xcassets/appicon.appiconset 31 | 32 | 33 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/Platforms/iOS/Program.cs: -------------------------------------------------------------------------------- 1 | using UIKit; 2 | 3 | namespace ValidationRulesTest; 4 | 5 | public class Program 6 | { 7 | // This is the main entry point of the application. 8 | static void Main(string[] args) 9 | { 10 | // if you want to use a different Application Delegate class from "AppDelegate" 11 | // you can specify it here. 12 | UIApplication.Main(args, null, typeof(AppDelegate)); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "Windows Machine": { 4 | "commandName": "MsixPackage", 5 | "nativeDebugging": false 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/Resources/Fonts/OpenSans-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luismts/ValidationRulesPlugin/be8e76caa78f30643c51b7dba50379e95c06837f/samples/Maui/ValidationRulesTest/ValidationRulesTest/Resources/Fonts/OpenSans-Regular.ttf -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/Resources/appicon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/Resources/appiconfg.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/ValidationRulesTest.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net6.0-android;net6.0-ios;net6.0-maccatalyst 5 | $(TargetFrameworks);net6.0-windows10.0.19041 6 | Exe 7 | ValidationRulesTest 8 | true 9 | true 10 | enable 11 | true 12 | 13 | 14 | ValidationRulesTest 15 | 16 | 17 | com.companyname.validationrulestest 18 | 19 | 20 | 1 21 | 22 | 23 | True 24 | 25 | 14.2 26 | 14.0 27 | 21.0 28 | 10.0.17763.0 29 | 10.0.17763.0 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | WinExe 58 | win10-x64 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/Validations/EmailRule.cs: -------------------------------------------------------------------------------- 1 | using Plugin.ValidationRules.Interfaces; 2 | using System.Text.RegularExpressions; 3 | 4 | namespace ValidationRulesTest.Validations 5 | { 6 | public class EmailRule : IValidationRule 7 | { 8 | 9 | public string ValidationMessage { get; set; } = "Email is not valid."; 10 | 11 | public bool Check(string value) 12 | { 13 | 14 | if (value == null) 15 | { 16 | ValidationMessage = "A email is required."; 17 | return false; 18 | } 19 | 20 | var str = value as string; 21 | 22 | Regex regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$"); 23 | Match match = regex.Match(str); 24 | 25 | if (!match.Success) 26 | ValidationMessage = "Email is not valid."; 27 | 28 | return match.Success; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/Validations/IsNotNullOrEmptyRule.cs: -------------------------------------------------------------------------------- 1 | using Plugin.ValidationRules.Interfaces; 2 | 3 | namespace ValidationRulesTest.Validations 4 | { 5 | public class IsNotNullOrEmptyRule : IValidationRule 6 | { 7 | public string ValidationMessage { get; set; } 8 | 9 | public bool Check(T value) 10 | { 11 | if (value == null) 12 | { 13 | return false; 14 | } 15 | 16 | var str = value as string; 17 | return !string.IsNullOrWhiteSpace(str); 18 | } 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/Validations/PasswordRule.cs: -------------------------------------------------------------------------------- 1 | using Plugin.ValidationRules.Interfaces; 2 | 3 | namespace ValidationRulesTest.Validations 4 | { 5 | public class PasswordRule : IValidationRule 6 | { 7 | public string ValidationMessage { get; set; } 8 | 9 | public bool Check(string value) 10 | { 11 | if (value == null) 12 | { 13 | ValidationMessage = "A password is required."; 14 | return false; 15 | } 16 | 17 | if (!char.IsLetter(value[0])) 18 | { 19 | ValidationMessage = "First character must be a letter."; 20 | return false; 21 | } 22 | 23 | if (!char.IsUpper(value[0])) 24 | { 25 | ValidationMessage = "First letter must be Capitalize."; 26 | return false; 27 | } 28 | 29 | if (value.Length < 8) 30 | { 31 | ValidationMessage = "Password length must be 8 characters minimum."; 32 | return false; 33 | } 34 | 35 | if (!value.Any(char.IsDigit)) 36 | { 37 | ValidationMessage = "Your password must contain numbers."; 38 | return false; 39 | } 40 | 41 | if (!value.Any(char.IsSymbol) && !value.Any(char.IsPunctuation)) 42 | { 43 | ValidationMessage = "Your password must contain symbols."; 44 | return false; 45 | } 46 | 47 | return true; // Yupiii ! We did !!! 48 | } 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/Validations/UserRule.cs: -------------------------------------------------------------------------------- 1 | using Plugin.ValidationRules.Interfaces; 2 | using ValidationRulesTest.Models; 3 | using System.Text.RegularExpressions; 4 | 5 | namespace ValidationRulesTest.Validations 6 | { 7 | public class UserRule : IValidationRule 8 | { 9 | public string ValidationMessage { get; set; } 10 | 11 | public bool Check(User value) 12 | { 13 | if (value == null) 14 | { 15 | throw new Exception(); 16 | } 17 | 18 | if (string.IsNullOrEmpty(value.Name)) 19 | { 20 | ValidationMessage = "A name is required."; 21 | return false; 22 | } 23 | 24 | if (string.IsNullOrEmpty(value.Email)) 25 | { 26 | ValidationMessage = "A email is required."; 27 | return false; 28 | } 29 | 30 | var str = value.Email as string; 31 | 32 | Regex regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$"); 33 | Match match = regex.Match(str); 34 | 35 | if (!match.Success) 36 | { 37 | ValidationMessage = "Email is not valid."; 38 | return false; 39 | } 40 | 41 | return true; // Yupiii !!! 42 | } 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/ViewModels/Example1ViewModel.cs: -------------------------------------------------------------------------------- 1 | using Plugin.ValidationRules; 2 | using ValidationRulesTest.Validations; 3 | 4 | namespace ValidationRulesTest.ViewModels 5 | { 6 | public class Example1ViewModel 7 | { 8 | ValidationUnit _unit1; 9 | 10 | public Example1ViewModel() 11 | { 12 | Name = new Validatable(); 13 | LastName = new Validatable(); 14 | Email = new Validatable(); 15 | 16 | _unit1 = new ValidationUnit(Name, LastName, Email); 17 | 18 | AddValidations(); 19 | } 20 | 21 | public Validatable LastName { get; set; } 22 | public Validatable Name { get; set; } 23 | public Validatable Email { get; set; } 24 | 25 | 26 | private void AddValidations() 27 | { 28 | // Name validations 29 | Name.Validations.Add(new IsNotNullOrEmptyRule { ValidationMessage = "A name is required." }); 30 | 31 | //Lastname validations 32 | LastName.Validations.Add(new IsNotNullOrEmptyRule { ValidationMessage = "A lastname is required." }); 33 | 34 | //Email validations 35 | Email.Validations.Add(new IsNotNullOrEmptyRule{ ValidationMessage = "A email is required." }); 36 | Email.Validations.Add(new EmailRule()); 37 | } 38 | 39 | public bool Validate() 40 | { 41 | //var isValidName = _name.Validate(); 42 | //var isValidLastname = _lastname.Validate(); 43 | //var isValidEmail = _email.Validate(); 44 | 45 | //return isValidName && isValidLastname && isValidEmail; 46 | return _unit1.Validate(); 47 | } 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/ViewModels/Example2ViewModel.cs: -------------------------------------------------------------------------------- 1 | using Plugin.ValidationRules.Extensions; 2 | using Plugin.ValidationRules; 3 | using ValidationRulesTest.Validations; 4 | using ValidationRulesTest.Models; 5 | 6 | namespace ValidationRulesTest.ViewModels 7 | { 8 | public class Example2ViewModel : ExtendedPropertyChanged 9 | { 10 | public Example2ViewModel() 11 | { 12 | _user = new Validatable(); 13 | _user.Value = new User(); 14 | 15 | AddValidations(); 16 | } 17 | 18 | private Validatable _user; 19 | public Validatable User 20 | { 21 | get => _user; 22 | set => SetProperty(ref _user, value); 23 | } 24 | 25 | private void AddValidations() 26 | { 27 | // Your validations goes here 28 | _user.Validations.Add(new UserRule()); 29 | } 30 | 31 | public bool Validate() 32 | { 33 | // Your logic goes here 34 | return User.Validate(); 35 | } 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/ViewModels/Example3ViewModel.cs: -------------------------------------------------------------------------------- 1 | using Plugin.ValidationRules.Extensions; 2 | using ValidationRulesTest.Models; 3 | 4 | namespace ValidationRulesTest.ViewModels 5 | { 6 | public class Example3ViewModel : ExtendedPropertyChanged 7 | { 8 | 9 | public Example3ViewModel() 10 | { 11 | _user = new UserValidator(); 12 | } 13 | 14 | private UserValidator _user; 15 | public UserValidator User 16 | { 17 | get => _user; 18 | set => SetProperty(ref _user, value); 19 | } 20 | 21 | public bool Validate() 22 | { 23 | // Your logic goes here 24 | return User.Validate(); 25 | } 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/ViewModels/Example4ViewModel.cs: -------------------------------------------------------------------------------- 1 | using Plugin.ValidationRules.Extensions; 2 | using ValidationRulesTest.Models; 3 | using Plugin.ValidationRules.Formatters; 4 | using System.Windows.Input; 5 | 6 | namespace ValidationRulesTest.ViewModels 7 | { 8 | public class Example4ViewModel : ExtendedPropertyChanged 9 | { 10 | 11 | public Example4ViewModel() 12 | { 13 | _user = new UserValidator(); 14 | 15 | _user.Name.Formatter = new StringCaseFormatter(StringCases.Capitalize); 16 | _user.LastName.Formatter = new StringCaseFormatter(StringCases.Upper); 17 | } 18 | 19 | private UserValidator _user; 20 | public UserValidator User 21 | { 22 | get => _user; 23 | set => SetProperty(ref _user, value); 24 | } 25 | 26 | public ICommand FillFormCommand => new Command(ExecuteFillFormCommand); 27 | 28 | void ExecuteFillFormCommand() 29 | { 30 | User.Name.Value = "Luis"; 31 | User.LastName.Value = "Matos"; 32 | User.Email.Value = "luismatos@luismts.com"; 33 | } 34 | 35 | public bool Validate() 36 | { 37 | // Your logic goes here 38 | MappingTest(); 39 | // Your logic goes here 40 | 41 | return User.Validate(); 42 | } 43 | 44 | private void MappingTest() 45 | { 46 | var stopper = new System.Diagnostics.Stopwatch(); 47 | var testRuns = 1000; // 1 second 48 | 49 | stopper.Start(); 50 | 51 | User modelUser = User.Map(); 52 | 53 | stopper.Stop(); 54 | 55 | var time1 = stopper.Elapsed.TotalMilliseconds / (double)testRuns; 56 | System.Console.WriteLine("ManualMapper: " + time1); // Elapsed time: 0.002 57 | 58 | stopper.Restart(); 59 | 60 | // Extension Mapper with simple Model 61 | var extMapperUser = User.MapValidator(); 62 | 63 | stopper.Stop(); 64 | 65 | var time2 = stopper.Elapsed.TotalMilliseconds / (double)testRuns; 66 | System.Console.WriteLine("ExtensionMapper: " + time2); // Elapsed time: 0.013 67 | } 68 | 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/ViewModels/Example5ViewModel.cs: -------------------------------------------------------------------------------- 1 | using Plugin.ValidationRules; 2 | using Plugin.ValidationRules.Extensions; 3 | using Plugin.ValidationRules.Rules; 4 | using ValidationRulesTest.Models; 5 | using ValidationRulesTest.Validations; 6 | using EmailRule = Plugin.ValidationRules.Rules.EmailRule; 7 | 8 | namespace ValidationRulesTest.ViewModels 9 | { 10 | public class Example5ViewModel 11 | { 12 | ValidationUnit _validationUnit; 13 | UserValidator2 _testModelValidator; 14 | 15 | public Example5ViewModel() 16 | { 17 | AddValidations(); 18 | } 19 | 20 | public Validatable LastName { get; set; } 21 | public Validatable Name { get; set; } 22 | public Validatable Email { get; set; } 23 | 24 | 25 | private void AddValidations() 26 | { 27 | Name = new Validatable( 28 | new NotEmptyRule("").WithMessage("A name is required."), 29 | new IsNotNullOrEmptyRule().WithMessage(() => "Hi!") 30 | ); 31 | 32 | LastName = Validator.Build() 33 | .IsRequired("A last name is required.") 34 | .Must(CustomValidation, "Last name need to be longer.") 35 | .When(x => Name.Validate()); 36 | 37 | //// You can add several Rules by this 38 | /// 39 | //Email = new Validatable( 40 | // new IsNotNullOrEmptyRule().WithMessage("A email is required."), 41 | // new EmailRule() 42 | //); 43 | 44 | // Or this 45 | Email = Validator.Build() 46 | //.Add(new IsNotNullOrEmptyRule(), "An email is required.") 47 | .IsRequired("An email is required.") 48 | .WithRule(new EmailRule()) 49 | .When(x => Name.Validate() && LastName.Validate()); 50 | 51 | // Add to the unit 52 | _validationUnit = new ValidationUnit(Name, LastName, Email); 53 | 54 | //var listValidatables = new List> { Name, LastName, Email }; 55 | //_validationUnit = new ValidationUnit(listValidatables); 56 | 57 | // Validator Model 58 | _testModelValidator = new UserValidator2(); 59 | } 60 | 61 | public bool Validate() 62 | { 63 | // Test model 64 | //var isValidModel = _testModelValidator.Validate(); 65 | 66 | return _validationUnit.Validate(); 67 | } 68 | 69 | private bool CustomValidation(string parameter) 70 | { 71 | return parameter?.Length > 3; 72 | } 73 | 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/ViewModels/Example6ViewModel.cs: -------------------------------------------------------------------------------- 1 | using Plugin.ValidationRules; 2 | using Plugin.ValidationRules.Extensions; 3 | using Plugin.ValidationRules.Formatters; 4 | 5 | namespace ValidationRulesTest.ViewModels 6 | { 7 | public class Example6ViewModel 8 | { 9 | public Example6ViewModel() 10 | { 11 | Name = Validator.Build().IsRequired("The name is required."); 12 | Phone = Validator.Build() 13 | .When(x => !string.IsNullOrEmpty(x)) 14 | .Must(x => x.Length == 12, "Minimum lenght is 12."); 15 | 16 | Phone.Formatter = new MaskFormatter("XXX-XXX-XXXX"); 17 | } 18 | 19 | public Validatable Name { get; set; } 20 | public Validatable Phone { get; set; } 21 | 22 | public bool Validate() 23 | { 24 | return Name.Validate() && Phone.Validate(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/ViewModels/Example7ViewModel.cs: -------------------------------------------------------------------------------- 1 | using Plugin.ValidationRules; 2 | using Plugin.ValidationRules.Extensions; 3 | using ValidationRulesTest.Validations; 4 | 5 | namespace ValidationRulesTest.ViewModels 6 | { 7 | public class Example7ViewModel 8 | { 9 | public Example7ViewModel() 10 | { 11 | Password = Validator.Build() 12 | .IsRequired("A password is required.") 13 | .WithRule(new PasswordRule()); 14 | 15 | ConfirmPassword = Validator.Build() 16 | .When(_ => !string.IsNullOrEmpty(Password.Value)) 17 | .Must(x => x == Password.Value, "Password is not matching."); 18 | } 19 | 20 | public Validatable Password { get; set; } 21 | public Validatable ConfirmPassword { get; set; } 22 | 23 | public bool Validate() 24 | { 25 | return Password.Validate() && ConfirmPassword.Validate(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/ViewModels/Example8ViewModel.cs: -------------------------------------------------------------------------------- 1 | using Plugin.ValidationRules; 2 | using Plugin.ValidationRules.Extensions; 3 | 4 | namespace ValidationRulesTest.ViewModels 5 | { 6 | public class Example8ViewModel 7 | { 8 | public Example8ViewModel() 9 | { 10 | Quantity = Validator.Build() 11 | .Must(value => value > 0, "Need to specify the quantity"); 12 | 13 | var monkeyList = new List(); 14 | monkeyList.Add("Baboon"); 15 | monkeyList.Add("Capuchin Monkey"); 16 | monkeyList.Add("Blue Monkey"); 17 | monkeyList.Add("Squirrel Monkey"); 18 | monkeyList.Add("Golden Lion Tamarin"); 19 | monkeyList.Add("Howler Monkey"); 20 | monkeyList.Add("Japanese Macaque"); 21 | 22 | MonkeyList = ValidatorList.Build() 23 | .AddItemsSource(monkeyList) 24 | .IsRequired("An item is required.") 25 | .Must(value => 26 | { 27 | if(MonkeyList.SelectedIndex == 2 && Quantity.Value < 5) // == blue monkey 28 | return false; 29 | 30 | return true; 31 | }, "Minimum quantity of this monkey is 5"); 32 | 33 | UnitValidation = new ValidationUnit(Quantity, MonkeyList); 34 | } 35 | 36 | public ValidationUnit UnitValidation; 37 | 38 | public Validatable Quantity { get; set; } 39 | public ValidatableList MonkeyList { get; set; } 40 | 41 | public bool Validate() 42 | { 43 | return Quantity.Validate() && MonkeyList.Validate(); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /samples/Maui/ValidationRulesTest/ValidationRulesTest/Views/Example1.xaml: -------------------------------------------------------------------------------- 1 |  2 | 8 | 9 | 10 | 11 |