├── .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 |
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 |
--------------------------------------------------------------------------------
/samples/Maui/ValidationRulesTest/ValidationRulesTest/Resources/appiconfg.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/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 |
12 |
13 |
18 |
22 |
23 |
28 |
32 |
33 |
38 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/samples/Maui/ValidationRulesTest/ValidationRulesTest/Views/Example1.xaml.cs:
--------------------------------------------------------------------------------
1 | using ValidationRulesTest.ViewModels;
2 |
3 | namespace ValidationRulesTest
4 | {
5 | public partial class Example1 : ContentPage
6 | {
7 | Example1ViewModel _context;
8 | public Example1()
9 | {
10 | InitializeComponent();
11 |
12 | _context = new ViewModels.Example1ViewModel();
13 | BindingContext = _context;
14 | }
15 |
16 | private void Button_Clicked(object sender, EventArgs e)
17 | {
18 | var isValid = _context.Validate();
19 |
20 | if (isValid)
21 | {
22 | DisplayAlert(":)", "This form is valid", "OK");
23 | }
24 | else
25 | {
26 | DisplayAlert(":(", "This form is not valid", "OK");
27 | }
28 | }
29 |
30 | private void nameEntry_Unfocused(object sender, FocusEventArgs e)
31 | {
32 | _context.Name.Validate();
33 | }
34 |
35 | private void lastnameEntry_Unfocused(object sender, FocusEventArgs e)
36 | {
37 | _context.LastName.Validate();
38 | }
39 |
40 | private void emailEntry_Unfocused(object sender, FocusEventArgs e)
41 | {
42 | _context.Email.Validate();
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/samples/Maui/ValidationRulesTest/ValidationRulesTest/Views/Example2.xaml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
15 |
16 |
20 |
21 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/samples/Maui/ValidationRulesTest/ValidationRulesTest/Views/Example2.xaml.cs:
--------------------------------------------------------------------------------
1 | using ValidationRulesTest.ViewModels;
2 |
3 | namespace ValidationRulesTest
4 | {
5 | public partial class Example2 : ContentPage
6 | {
7 | Example2ViewModel _context;
8 | public Example2()
9 | {
10 | InitializeComponent();
11 |
12 | _context = new Example2ViewModel();
13 | BindingContext = _context;
14 | }
15 |
16 | private void Button_Clicked(object sender, EventArgs e)
17 | {
18 | var isValid = _context.Validate();
19 |
20 | if (isValid)
21 | {
22 | DisplayAlert(":)", "This form is valid", "OK");
23 | }
24 | else
25 | {
26 | DisplayAlert(":(", $"This form is not valid. {_context.User.Error}", "OK");
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/samples/Maui/ValidationRulesTest/ValidationRulesTest/Views/Example3.xaml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
16 |
20 |
21 |
26 |
30 |
31 |
36 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/samples/Maui/ValidationRulesTest/ValidationRulesTest/Views/Example3.xaml.cs:
--------------------------------------------------------------------------------
1 | using ValidationRulesTest.ViewModels;
2 |
3 | namespace ValidationRulesTest
4 | {
5 | public partial class Example3 : ContentPage
6 | {
7 | Example3ViewModel _context;
8 | public Example3()
9 | {
10 | InitializeComponent();
11 |
12 | _context = new Example3ViewModel();
13 | BindingContext = _context;
14 | }
15 |
16 | private void Button_Clicked(object sender, EventArgs e)
17 | {
18 | var isValid = _context.Validate();
19 |
20 | if (isValid)
21 | {
22 | DisplayAlert(":)", "This form is valid", "OK");
23 | }
24 | else
25 | {
26 | DisplayAlert(":(", "This form is not valid", "OK");
27 | }
28 | }
29 |
30 | private void nameEntry_Unfocused(object sender, FocusEventArgs e)
31 | {
32 | _context.User.Name.Validate();
33 | }
34 |
35 | private void lastnameEntry_Unfocused(object sender, FocusEventArgs e)
36 | {
37 | _context.User.LastName.Validate();
38 | }
39 |
40 | private void emailEntry_Unfocused(object sender, FocusEventArgs e)
41 | {
42 | _context.User.Email.Validate();
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/samples/Maui/ValidationRulesTest/ValidationRulesTest/Views/Example4.xaml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
23 |
24 |
28 |
29 |
30 |
31 |
32 |
36 |
37 |
41 |
42 |
43 |
44 |
45 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/samples/Maui/ValidationRulesTest/ValidationRulesTest/Views/Example4.xaml.cs:
--------------------------------------------------------------------------------
1 | using ValidationRulesTest.ViewModels;
2 |
3 | namespace ValidationRulesTest
4 | {
5 | public partial class Example4 : ContentPage
6 | {
7 | Example4ViewModel _context;
8 | public Example4()
9 | {
10 | InitializeComponent();
11 |
12 | _context = new Example4ViewModel();
13 | BindingContext = _context;
14 | }
15 |
16 | private void Button_Clicked(object sender, EventArgs e)
17 | {
18 | var isValid = _context.Validate();
19 |
20 | if (isValid)
21 | {
22 | DisplayAlert(":)", "This form is valid", "OK");
23 | }
24 | else
25 | {
26 | DisplayAlert(":(", "This form is not valid", "OK");
27 | }
28 | }
29 |
30 | private void Button_Clicked_1(object sender, EventArgs e)
31 | {
32 | // Test clear all 1
33 | _context.User.Name.Value = null;
34 | _context.User.LastName.Value = null;
35 | _context.User.Email.Value = null;
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/samples/Maui/ValidationRulesTest/ValidationRulesTest/Views/Example5.xaml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
23 |
24 |
28 |
29 |
30 |
31 |
32 |
36 |
37 |
41 |
42 |
43 |
44 |
45 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/samples/Maui/ValidationRulesTest/ValidationRulesTest/Views/Example5.xaml.cs:
--------------------------------------------------------------------------------
1 | using ValidationRulesTest.ViewModels;
2 |
3 | namespace ValidationRulesTest
4 | {
5 | public partial class Example5 : ContentPage
6 | {
7 | Example5ViewModel _context;
8 | public Example5()
9 | {
10 | InitializeComponent();
11 |
12 | _context = new Example5ViewModel();
13 | BindingContext = _context;
14 | }
15 |
16 | private void Button_Clicked(object sender, EventArgs e)
17 | {
18 | var isValid = _context.Validate();
19 |
20 | if (isValid)
21 | {
22 | DisplayAlert(":)", "This form is valid", "OK");
23 | }
24 | else
25 | {
26 | DisplayAlert(":(", "This form is not valid", "OK");
27 | }
28 | }
29 |
30 | private void Button_Clicked_1(object sender, EventArgs e)
31 | {
32 | // Test clear all 1
33 | _context.Name.Value = null;
34 | _context.LastName.Value = null;
35 | _context.Email.Value = null;
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/samples/Maui/ValidationRulesTest/ValidationRulesTest/Views/Example6.xaml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
23 |
24 |
28 |
29 |
30 |
31 |
32 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/samples/Maui/ValidationRulesTest/ValidationRulesTest/Views/Example6.xaml.cs:
--------------------------------------------------------------------------------
1 | using ValidationRulesTest.ViewModels;
2 |
3 | namespace ValidationRulesTest.Views
4 | {
5 | [XamlCompilation(XamlCompilationOptions.Compile)]
6 | public partial class Example6 : ContentPage
7 | {
8 | Example6ViewModel _context;
9 | public Example6 ()
10 | {
11 | InitializeComponent ();
12 |
13 | _context = new Example6ViewModel();
14 | BindingContext = _context;
15 | }
16 |
17 | private void Button_Clicked(object sender, EventArgs e)
18 | {
19 | var isValid = _context.Validate();
20 |
21 | if (isValid)
22 | {
23 | DisplayAlert(":)", "This form is valid", "OK");
24 | }
25 | else
26 | {
27 | DisplayAlert(":(", "This form is not valid", "OK");
28 | }
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/samples/Maui/ValidationRulesTest/ValidationRulesTest/Views/Example7.xaml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
12 |
17 |
18 |
19 |
20 |
21 |
25 |
26 |
31 |
32 |
33 |
34 |
35 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/samples/Maui/ValidationRulesTest/ValidationRulesTest/Views/Example7.xaml.cs:
--------------------------------------------------------------------------------
1 | using ValidationRulesTest.ViewModels;
2 |
3 | namespace ValidationRulesTest.Views
4 | {
5 | [XamlCompilation(XamlCompilationOptions.Compile)]
6 | public partial class Example7 : ContentPage
7 | {
8 | Example7ViewModel _context;
9 | public Example7()
10 | {
11 | InitializeComponent();
12 |
13 | _context = new Example7ViewModel();
14 | BindingContext = _context;
15 | }
16 |
17 | private void Button_Clicked(object sender, EventArgs e)
18 | {
19 | var isValid = _context.Validate();
20 |
21 | if (isValid)
22 | {
23 | DisplayAlert(":)", "This form is valid", "OK");
24 | }
25 | else
26 | {
27 | DisplayAlert(":(", "This form is not valid", "OK");
28 | }
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/samples/Maui/ValidationRulesTest/ValidationRulesTest/Views/Example8.xaml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
12 |
16 |
17 |
18 |
19 |
20 |
24 |
25 |
29 |
30 |
31 |
32 |
33 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/samples/Maui/ValidationRulesTest/ValidationRulesTest/Views/Example8.xaml.cs:
--------------------------------------------------------------------------------
1 | using ValidationRulesTest.ViewModels;
2 |
3 | namespace ValidationRulesTest.Views
4 | {
5 | [XamlCompilation(XamlCompilationOptions.Compile)]
6 | public partial class Example8 : ContentPage
7 | {
8 | Example8ViewModel _context;
9 | public Example8()
10 | {
11 | try
12 | {
13 | InitializeComponent();
14 |
15 | _context = new Example8ViewModel();
16 | BindingContext = _context;
17 | }
18 | catch (Exception e)
19 | {
20 |
21 | throw;
22 | }
23 | }
24 |
25 | private void Button_Clicked(object sender, EventArgs e)
26 | {
27 | //var isValid = _context.Validate();
28 | var isValid = _context.UnitValidation.Validate();
29 |
30 | if (isValid)
31 | {
32 | DisplayAlert(":)", "This form is valid", "OK");
33 | }
34 | else
35 | {
36 | var error = _context.UnitValidation.Error;
37 | DisplayAlert(":(", error, "OK");
38 | }
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/samples/Maui/ValidationRulesTest/ValidationRulesTest/Views/Examples.xaml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
17 |
18 |
22 |
26 |
30 |
34 |
35 |
39 |
40 |
44 |
45 |
49 |
50 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/samples/Maui/ValidationRulesTest/ValidationRulesTest/Views/Examples.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace ValidationRulesTest.Views
2 | {
3 | [XamlCompilation(XamlCompilationOptions.Compile)]
4 | public partial class Examples : ContentPage
5 | {
6 | public Examples()
7 | {
8 | InitializeComponent();
9 | }
10 |
11 | private void example1_Clicked(object sender, EventArgs e)
12 | {
13 | Navigation.PushAsync(new Example1());
14 | }
15 |
16 | private void example2_Clicked(object sender, EventArgs e)
17 | {
18 | Navigation.PushAsync(new Example2());
19 | }
20 |
21 | private void example3_Clicked(object sender, EventArgs e)
22 | {
23 | Navigation.PushAsync(new Example3());
24 | }
25 |
26 | private void example4_Clicked(object sender, EventArgs e)
27 | {
28 | Navigation.PushAsync(new Example4());
29 | }
30 |
31 | private void example5_Clicked(object sender, EventArgs e)
32 | {
33 | Navigation.PushAsync(new Example5());
34 | }
35 |
36 | private void example6_Clicked(object sender, EventArgs e)
37 | {
38 | Navigation.PushAsync(new Example6());
39 | }
40 |
41 | private void example7_Clicked(object sender, EventArgs e)
42 | {
43 | Navigation.PushAsync(new Example7());
44 | }
45 |
46 | private void example8_Clicked(object sender, EventArgs e)
47 | {
48 | Navigation.PushAsync(new Example8());
49 | }
50 | }
51 | }
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.Android/Assets/AboutAssets.txt:
--------------------------------------------------------------------------------
1 | Any raw assets you want to be deployed with your application can be placed in
2 | this directory (and child directories) and given a Build Action of "AndroidAsset".
3 |
4 | These files will be deployed with you package and will be accessible using Android's
5 | AssetManager, like this:
6 |
7 | public class ReadAsset : Activity
8 | {
9 | protected override void OnCreate (Bundle bundle)
10 | {
11 | base.OnCreate (bundle);
12 |
13 | InputStream input = Assets.Open ("my_asset.txt");
14 | }
15 | }
16 |
17 | Additionally, some Android functions will automatically load asset files:
18 |
19 | Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf");
20 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.Android/MainActivity.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using Android.App;
4 | using Android.Content.PM;
5 | using Android.Runtime;
6 | using Android.Views;
7 | using Android.Widget;
8 | using Android.OS;
9 |
10 | namespace ValidationRulesTest.Droid
11 | {
12 | [Activity(Label = "ValidationRulesTest", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
13 | public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
14 | {
15 | protected override void OnCreate(Bundle savedInstanceState)
16 | {
17 | TabLayoutResource = Resource.Layout.Tabbar;
18 | ToolbarResource = Resource.Layout.Toolbar;
19 |
20 | base.OnCreate(savedInstanceState);
21 | global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
22 | LoadApplication(new App());
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.Android/Properties/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.Android/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 | using Android.App;
5 |
6 | // General Information about an assembly is controlled through the following
7 | // set of attributes. Change these attribute values to modify the information
8 | // associated with an assembly.
9 | [assembly: AssemblyTitle("ValidationRulesTest.Android")]
10 | [assembly: AssemblyDescription("")]
11 | [assembly: AssemblyConfiguration("")]
12 | [assembly: AssemblyCompany("")]
13 | [assembly: AssemblyProduct("ValidationRulesTest.Android")]
14 | [assembly: AssemblyCopyright("Copyright © 2014")]
15 | [assembly: AssemblyTrademark("")]
16 | [assembly: AssemblyCulture("")]
17 | [assembly: ComVisible(false)]
18 |
19 | // Version information for an assembly consists of the following four values:
20 | //
21 | // Major Version
22 | // Minor Version
23 | // Build Number
24 | // Revision
25 | //
26 | // You can specify all the values or you can default the Build and Revision Numbers
27 | // by using the '*' as shown below:
28 | // [assembly: AssemblyVersion("1.0.*")]
29 | [assembly: AssemblyVersion("1.0.0.0")]
30 | [assembly: AssemblyFileVersion("1.0.0.0")]
31 |
32 | // Add some common permissions, these can be removed if not needed
33 | [assembly: UsesPermission(Android.Manifest.Permission.Internet)]
34 | [assembly: UsesPermission(Android.Manifest.Permission.WriteExternalStorage)]
35 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.Android/Resources/AboutResources.txt:
--------------------------------------------------------------------------------
1 | Images, layout descriptions, binary blobs and string dictionaries can be included
2 | in your application as resource files. Various Android APIs are designed to
3 | operate on the resource IDs instead of dealing with images, strings or binary blobs
4 | directly.
5 |
6 | For example, a sample Android app that contains a user interface layout (main.xml),
7 | an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png)
8 | would keep its resources in the "Resources" directory of the application:
9 |
10 | Resources/
11 | drawable-hdpi/
12 | icon.png
13 |
14 | drawable-ldpi/
15 | icon.png
16 |
17 | drawable-mdpi/
18 | icon.png
19 |
20 | layout/
21 | main.xml
22 |
23 | values/
24 | strings.xml
25 |
26 | In order to get the build system to recognize Android resources, set the build action to
27 | "AndroidResource". The native Android APIs do not operate directly with filenames, but
28 | instead operate on resource IDs. When you compile an Android application that uses resources,
29 | the build system will package the resources for distribution and generate a class called
30 | "Resource" that contains the tokens for each one of the resources included. For example,
31 | for the above Resources layout, this is what the Resource class would expose:
32 |
33 | public class Resource {
34 | public class drawable {
35 | public const int icon = 0x123;
36 | }
37 |
38 | public class layout {
39 | public const int main = 0x456;
40 | }
41 |
42 | public class strings {
43 | public const int first_string = 0xabc;
44 | public const int second_string = 0xbcd;
45 | }
46 | }
47 |
48 | You would then use R.drawable.icon to reference the drawable/icon.png file, or Resource.layout.main
49 | to reference the layout/main.xml file, or Resource.strings.first_string to reference the first
50 | string in the dictionary file values/strings.xml.
51 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.Android/Resources/layout/Tabbar.axml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.Android/Resources/layout/Toolbar.axml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.Android/Resources/mipmap-anydpi-v26/icon.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.Android/Resources/mipmap-anydpi-v26/icon_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.Android/Resources/mipmap-hdpi/Icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luismts/ValidationRulesPlugin/be8e76caa78f30643c51b7dba50379e95c06837f/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.Android/Resources/mipmap-hdpi/Icon.png
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.Android/Resources/mipmap-hdpi/launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luismts/ValidationRulesPlugin/be8e76caa78f30643c51b7dba50379e95c06837f/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.Android/Resources/mipmap-hdpi/launcher_foreground.png
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.Android/Resources/mipmap-mdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luismts/ValidationRulesPlugin/be8e76caa78f30643c51b7dba50379e95c06837f/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.Android/Resources/mipmap-mdpi/icon.png
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.Android/Resources/mipmap-mdpi/launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luismts/ValidationRulesPlugin/be8e76caa78f30643c51b7dba50379e95c06837f/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.Android/Resources/mipmap-mdpi/launcher_foreground.png
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.Android/Resources/mipmap-xhdpi/Icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luismts/ValidationRulesPlugin/be8e76caa78f30643c51b7dba50379e95c06837f/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.Android/Resources/mipmap-xhdpi/Icon.png
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.Android/Resources/mipmap-xhdpi/launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luismts/ValidationRulesPlugin/be8e76caa78f30643c51b7dba50379e95c06837f/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.Android/Resources/mipmap-xhdpi/launcher_foreground.png
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.Android/Resources/mipmap-xxhdpi/Icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luismts/ValidationRulesPlugin/be8e76caa78f30643c51b7dba50379e95c06837f/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.Android/Resources/mipmap-xxhdpi/Icon.png
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.Android/Resources/mipmap-xxhdpi/launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luismts/ValidationRulesPlugin/be8e76caa78f30643c51b7dba50379e95c06837f/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.Android/Resources/mipmap-xxhdpi/launcher_foreground.png
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.Android/Resources/mipmap-xxxhdpi/Icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luismts/ValidationRulesPlugin/be8e76caa78f30643c51b7dba50379e95c06837f/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.Android/Resources/mipmap-xxxhdpi/Icon.png
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.Android/Resources/mipmap-xxxhdpi/launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luismts/ValidationRulesPlugin/be8e76caa78f30643c51b7dba50379e95c06837f/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.Android/Resources/mipmap-xxxhdpi/launcher_foreground.png
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.Android/Resources/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFFFFF
4 | #3F51B5
5 | #303F9F
6 | #FF4081
7 |
8 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.Android/Resources/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
7 |
26 |
27 |
30 |
31 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/AppDelegate.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | using Foundation;
6 | using UIKit;
7 |
8 | namespace ValidationRulesTest.iOS
9 | {
10 | // The UIApplicationDelegate for the application. This class is responsible for launching the
11 | // User Interface of the application, as well as listening (and optionally responding) to
12 | // application events from iOS.
13 | [Register("AppDelegate")]
14 | public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
15 | {
16 | //
17 | // This method is invoked when the application has loaded and is ready to run. In this
18 | // method you should instantiate the window, load the UI into it and then make the window
19 | // visible.
20 | //
21 | // You have 17 seconds to return from this method, or iOS will terminate your application.
22 | //
23 | public override bool FinishedLaunching(UIApplication app, NSDictionary options)
24 | {
25 | global::Xamarin.Forms.Forms.Init();
26 | LoadApplication(new App());
27 |
28 | return base.FinishedLaunching(app, options);
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images": [
3 | {
4 | "scale": "2x",
5 | "size": "20x20",
6 | "idiom": "iphone",
7 | "filename": "Icon40.png"
8 | },
9 | {
10 | "scale": "3x",
11 | "size": "20x20",
12 | "idiom": "iphone",
13 | "filename": "Icon60.png"
14 | },
15 | {
16 | "scale": "2x",
17 | "size": "29x29",
18 | "idiom": "iphone",
19 | "filename": "Icon58.png"
20 | },
21 | {
22 | "scale": "3x",
23 | "size": "29x29",
24 | "idiom": "iphone",
25 | "filename": "Icon87.png"
26 | },
27 | {
28 | "scale": "2x",
29 | "size": "40x40",
30 | "idiom": "iphone",
31 | "filename": "Icon80.png"
32 | },
33 | {
34 | "scale": "3x",
35 | "size": "40x40",
36 | "idiom": "iphone",
37 | "filename": "Icon120.png"
38 | },
39 | {
40 | "scale": "2x",
41 | "size": "60x60",
42 | "idiom": "iphone",
43 | "filename": "Icon120.png"
44 | },
45 | {
46 | "scale": "3x",
47 | "size": "60x60",
48 | "idiom": "iphone",
49 | "filename": "Icon180.png"
50 | },
51 | {
52 | "scale": "1x",
53 | "size": "20x20",
54 | "idiom": "ipad",
55 | "filename": "Icon20.png"
56 | },
57 | {
58 | "scale": "2x",
59 | "size": "20x20",
60 | "idiom": "ipad",
61 | "filename": "Icon40.png"
62 | },
63 | {
64 | "scale": "1x",
65 | "size": "29x29",
66 | "idiom": "ipad",
67 | "filename": "Icon29.png"
68 | },
69 | {
70 | "scale": "2x",
71 | "size": "29x29",
72 | "idiom": "ipad",
73 | "filename": "Icon58.png"
74 | },
75 | {
76 | "scale": "1x",
77 | "size": "40x40",
78 | "idiom": "ipad",
79 | "filename": "Icon40.png"
80 | },
81 | {
82 | "scale": "2x",
83 | "size": "40x40",
84 | "idiom": "ipad",
85 | "filename": "Icon80.png"
86 | },
87 | {
88 | "scale": "1x",
89 | "size": "76x76",
90 | "idiom": "ipad",
91 | "filename": "Icon76.png"
92 | },
93 | {
94 | "scale": "2x",
95 | "size": "76x76",
96 | "idiom": "ipad",
97 | "filename": "Icon152.png"
98 | },
99 | {
100 | "scale": "2x",
101 | "size": "83.5x83.5",
102 | "idiom": "ipad",
103 | "filename": "Icon167.png"
104 | },
105 | {
106 | "scale": "1x",
107 | "size": "1024x1024",
108 | "idiom": "ios-marketing",
109 | "filename": "Icon1024.png"
110 | }
111 | ],
112 | "properties": {},
113 | "info": {
114 | "version": 1,
115 | "author": "xcode"
116 | }
117 | }
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Assets.xcassets/AppIcon.appiconset/Icon1024.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luismts/ValidationRulesPlugin/be8e76caa78f30643c51b7dba50379e95c06837f/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Assets.xcassets/AppIcon.appiconset/Icon1024.png
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Assets.xcassets/AppIcon.appiconset/Icon120.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luismts/ValidationRulesPlugin/be8e76caa78f30643c51b7dba50379e95c06837f/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Assets.xcassets/AppIcon.appiconset/Icon120.png
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Assets.xcassets/AppIcon.appiconset/Icon152.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luismts/ValidationRulesPlugin/be8e76caa78f30643c51b7dba50379e95c06837f/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Assets.xcassets/AppIcon.appiconset/Icon152.png
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Assets.xcassets/AppIcon.appiconset/Icon167.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luismts/ValidationRulesPlugin/be8e76caa78f30643c51b7dba50379e95c06837f/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Assets.xcassets/AppIcon.appiconset/Icon167.png
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Assets.xcassets/AppIcon.appiconset/Icon180.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luismts/ValidationRulesPlugin/be8e76caa78f30643c51b7dba50379e95c06837f/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Assets.xcassets/AppIcon.appiconset/Icon180.png
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Assets.xcassets/AppIcon.appiconset/Icon20.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luismts/ValidationRulesPlugin/be8e76caa78f30643c51b7dba50379e95c06837f/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Assets.xcassets/AppIcon.appiconset/Icon20.png
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Assets.xcassets/AppIcon.appiconset/Icon29.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luismts/ValidationRulesPlugin/be8e76caa78f30643c51b7dba50379e95c06837f/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Assets.xcassets/AppIcon.appiconset/Icon29.png
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Assets.xcassets/AppIcon.appiconset/Icon40.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luismts/ValidationRulesPlugin/be8e76caa78f30643c51b7dba50379e95c06837f/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Assets.xcassets/AppIcon.appiconset/Icon40.png
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Assets.xcassets/AppIcon.appiconset/Icon58.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luismts/ValidationRulesPlugin/be8e76caa78f30643c51b7dba50379e95c06837f/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Assets.xcassets/AppIcon.appiconset/Icon58.png
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Assets.xcassets/AppIcon.appiconset/Icon60.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luismts/ValidationRulesPlugin/be8e76caa78f30643c51b7dba50379e95c06837f/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Assets.xcassets/AppIcon.appiconset/Icon60.png
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Assets.xcassets/AppIcon.appiconset/Icon76.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luismts/ValidationRulesPlugin/be8e76caa78f30643c51b7dba50379e95c06837f/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Assets.xcassets/AppIcon.appiconset/Icon76.png
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Assets.xcassets/AppIcon.appiconset/Icon80.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luismts/ValidationRulesPlugin/be8e76caa78f30643c51b7dba50379e95c06837f/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Assets.xcassets/AppIcon.appiconset/Icon80.png
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Assets.xcassets/AppIcon.appiconset/Icon87.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luismts/ValidationRulesPlugin/be8e76caa78f30643c51b7dba50379e95c06837f/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Assets.xcassets/AppIcon.appiconset/Icon87.png
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Entitlements.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | UIDeviceFamily
6 |
7 | 1
8 | 2
9 |
10 | UISupportedInterfaceOrientations
11 |
12 | UIInterfaceOrientationPortrait
13 | UIInterfaceOrientationLandscapeLeft
14 | UIInterfaceOrientationLandscapeRight
15 |
16 | UISupportedInterfaceOrientations~ipad
17 |
18 | UIInterfaceOrientationPortrait
19 | UIInterfaceOrientationPortraitUpsideDown
20 | UIInterfaceOrientationLandscapeLeft
21 | UIInterfaceOrientationLandscapeRight
22 |
23 | MinimumOSVersion
24 | 8.0
25 | CFBundleDisplayName
26 | ValidationRulesTest
27 | CFBundleIdentifier
28 | com.companyname.ValidationRulesTest
29 | CFBundleVersion
30 | 1.0
31 | UILaunchStoryboardName
32 | LaunchScreen
33 | CFBundleName
34 | ValidationRulesTest
35 | XSAppIconAssets
36 | Assets.xcassets/AppIcon.appiconset
37 |
38 |
39 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Main.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | using Foundation;
6 | using UIKit;
7 |
8 | namespace ValidationRulesTest.iOS
9 | {
10 | public class Application
11 | {
12 | // This is the main entry point of the application.
13 | static void Main(string[] args)
14 | {
15 | // if you want to use a different Application Delegate class from "AppDelegate"
16 | // you can specify it here.
17 | UIApplication.Main(args, null, "AppDelegate");
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("ValidationRulesTest.iOS")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("ValidationRulesTest.iOS")]
13 | [assembly: AssemblyCopyright("Copyright © 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("72bdc44f-c588-44f3-b6df-9aace7daafdd")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Resources/Default-568h@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luismts/ValidationRulesPlugin/be8e76caa78f30643c51b7dba50379e95c06837f/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Resources/Default-568h@2x.png
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Resources/Default-Portrait.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luismts/ValidationRulesPlugin/be8e76caa78f30643c51b7dba50379e95c06837f/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Resources/Default-Portrait.png
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Resources/Default-Portrait@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luismts/ValidationRulesPlugin/be8e76caa78f30643c51b7dba50379e95c06837f/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Resources/Default-Portrait@2x.png
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Resources/Default.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luismts/ValidationRulesPlugin/be8e76caa78f30643c51b7dba50379e95c06837f/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Resources/Default.png
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Resources/Default@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luismts/ValidationRulesPlugin/be8e76caa78f30643c51b7dba50379e95c06837f/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Resources/Default@2x.png
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest.iOS/Resources/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
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 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest/App.xaml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using ValidationRulesTest.Views;
3 | using Xamarin.Forms;
4 | using Xamarin.Forms.Xaml;
5 |
6 | [assembly: XamlCompilation(XamlCompilationOptions.Compile)]
7 | namespace ValidationRulesTest
8 | {
9 | public partial class App : Application
10 | {
11 | public App()
12 | {
13 | InitializeComponent();
14 |
15 | MainPage = new NavigationPage(new Examples());
16 | }
17 |
18 | protected override void OnStart()
19 | {
20 | // Handle when your app starts
21 | }
22 |
23 | protected override void OnSleep()
24 | {
25 | // Handle when your app sleeps
26 | }
27 |
28 | protected override void OnResume()
29 | {
30 | // Handle when your app resumes
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest/Behaviors/BehaviorBase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Xamarin.Forms;
3 |
4 | namespace ValidationRulesTest.Behaviors
5 | {
6 | ///
7 | /// Base class that extends on Xamarin Forms Behaviors.
8 | ///
9 | ///
10 | public class BehaviorBase : Behavior where T : BindableObject
11 | {
12 | ///
13 | /// The Object associated with the Behavior
14 | ///
15 | public T AssociatedObject { get; private set; }
16 |
17 | ///
18 | protected override void OnAttachedTo(T bindable)
19 | {
20 | base.OnAttachedTo(bindable);
21 | AssociatedObject = bindable;
22 |
23 | if (bindable.BindingContext != null)
24 | {
25 | BindingContext = bindable.BindingContext;
26 | }
27 |
28 | bindable.BindingContextChanged += OnBindingContextChanged;
29 | }
30 |
31 | ///
32 | protected override void OnDetachingFrom(T bindable)
33 | {
34 | base.OnDetachingFrom(bindable);
35 | bindable.BindingContextChanged -= OnBindingContextChanged;
36 | AssociatedObject = null;
37 | }
38 |
39 | void OnBindingContextChanged(object sender, EventArgs e)
40 | {
41 | OnBindingContextChanged();
42 | }
43 |
44 | ///
45 | protected override void OnBindingContextChanged()
46 | {
47 | base.OnBindingContextChanged();
48 | BindingContext = AssociatedObject.BindingContext;
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest/Models/User.cs:
--------------------------------------------------------------------------------
1 | using Plugin.ValidationRules;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace ValidationRulesTest.Models
7 | {
8 | public class User
9 | {
10 | public string LastName { get; set; }
11 | public string Name { get; set; }
12 | public string Email { get; set; }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest/Models/UserValidator.cs:
--------------------------------------------------------------------------------
1 | using Plugin.ValidationRules;
2 | using Plugin.ValidationRules.Extensions;
3 | using Plugin.ValidationRules.Interfaces;
4 | using ValidationRulesTest.Validations;
5 |
6 | namespace ValidationRulesTest.Models
7 | {
8 | public class UserValidator : IMapperValidator
9 | {
10 | ValidationUnit _unit1;
11 |
12 | public UserValidator()
13 | {
14 | LastName = new Validatable();
15 | Name = new Validatable();
16 | Email = new Validatable();
17 |
18 | _unit1 = new ValidationUnit(Name, LastName, Email);
19 |
20 | // Name validations
21 | Name.Validations.Add(new IsNotNullOrEmptyRule { ValidationMessage = "A name is required." });
22 |
23 | //Lastname validations
24 | LastName.Validations.Add(new IsNotNullOrEmptyRule { ValidationMessage = "A lastname is required." });
25 |
26 | //Email validations
27 | Email.Validations.Add(new IsNotNullOrEmptyRule { ValidationMessage = "A email is required." });
28 | Email.Validations.Add(new EmailRule());
29 | }
30 |
31 | public Validatable LastName { get; set; }
32 | public Validatable Name { get; set; }
33 | public Validatable Email { get; set; }
34 |
35 | public bool Validate()
36 | {
37 | // Your logic goes here
38 | return _unit1.Validate();
39 | }
40 |
41 | public User Map()
42 | {
43 | // Simple Manual Mapper
44 | var manualMapperUser = new User
45 | {
46 | Name = this.Name.Value,
47 | LastName = this.LastName.Value,
48 | Email = this.Email.Value
49 | };
50 |
51 | return manualMapperUser;
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest/Models/UserValidator2.cs:
--------------------------------------------------------------------------------
1 | using Plugin.ValidationRules;
2 | using Plugin.ValidationRules.Extensions;
3 | using Plugin.ValidationRules.Interfaces;
4 | using ValidationRulesTest.Validations;
5 |
6 | namespace ValidationRulesTest.Models
7 | {
8 | public class UserValidator2 : Validator
9 | {
10 | public UserValidator2()
11 | {
12 | //Name validations
13 | Name = Build()
14 | .WithRule(new IsNotNullOrEmptyRule(), "A name is required.");
15 |
16 | //Lastname validations
17 | LastName = Build()
18 | .WithRule(new IsNotNullOrEmptyRule(), "A lastname is required.");
19 |
20 | //Email validations
21 | Email = Build()
22 | .IsRequired("A email is required.")
23 | .WithRule(new EmailRule());
24 |
25 | InitUnit();
26 | }
27 |
28 | public Validatable LastName { get; set; }
29 | public Validatable Name { get; set; }
30 | public Validatable Email { get; set; }
31 |
32 | //public override bool Validate()
33 | //{
34 | // Your logic goes here
35 | // return _unit1.Validate();
36 | //}
37 |
38 | public override User Map()
39 | {
40 | // Simple Manual Mapper
41 | var manualMapperUser = new User
42 | {
43 | Name = this.Name.Value,
44 | LastName = this.LastName.Value,
45 | Email = this.Email.Value
46 | };
47 |
48 | return manualMapperUser;
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest/ValidationRulesTest.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 |
6 |
7 |
8 | pdbonly
9 | true
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | Example1.xaml
23 |
24 |
25 | Example2.xaml
26 |
27 |
28 | Example5.xaml
29 |
30 |
31 | Example4.xaml
32 |
33 |
34 | Example3.xaml
35 |
36 |
37 | Example8.xaml
38 |
39 |
40 |
41 |
42 |
43 | MSBuild:UpdateDesignTimeXaml
44 |
45 |
46 | MSBuild:UpdateDesignTimeXaml
47 |
48 |
49 | MSBuild:UpdateDesignTimeXaml
50 |
51 |
52 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/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/Xamarin.Forms/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/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest/Validations/PasswordRule.cs:
--------------------------------------------------------------------------------
1 | using Plugin.ValidationRules.Interfaces;
2 | using System;
3 | using ValidationRulesTest.Models;
4 | using System.Text.RegularExpressions;
5 | using System.Linq;
6 |
7 | namespace ValidationRulesTest.Validations
8 | {
9 | public class PasswordRule : IValidationRule
10 | {
11 | public string ValidationMessage { get; set; }
12 |
13 | public bool Check(string value)
14 | {
15 | if (value == null)
16 | {
17 | ValidationMessage = "A password is required.";
18 | return false;
19 | }
20 |
21 | if (!char.IsLetter(value[0]))
22 | {
23 | ValidationMessage = "First character must be a letter.";
24 | return false;
25 | }
26 |
27 | if (!char.IsUpper(value[0]))
28 | {
29 | ValidationMessage = "First letter must be Capitalize.";
30 | return false;
31 | }
32 |
33 | if (value.Length < 8)
34 | {
35 | ValidationMessage = "Password length must be 8 characters minimum.";
36 | return false;
37 | }
38 |
39 | if (!value.Any(char.IsDigit))
40 | {
41 | ValidationMessage = "Your password must contain numbers.";
42 | return false;
43 | }
44 |
45 | if (!value.Any(char.IsSymbol) && !value.Any(char.IsPunctuation))
46 | {
47 | ValidationMessage = "Your password must contain symbols.";
48 | return false;
49 | }
50 |
51 | return true; // Yupiii ! We did !!!
52 | }
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest/Validations/UserRule.cs:
--------------------------------------------------------------------------------
1 | using Plugin.ValidationRules.Interfaces;
2 | using System;
3 | using ValidationRulesTest.Models;
4 | using System.Text.RegularExpressions;
5 |
6 | namespace ValidationRulesTest.Validations
7 | {
8 | public class UserRule : IValidationRule
9 | {
10 | public string ValidationMessage { get; set; }
11 |
12 | public bool Check(User value)
13 | {
14 | if (value == null)
15 | {
16 | throw new Exception();
17 | }
18 |
19 | if (string.IsNullOrEmpty(value.Name))
20 | {
21 | ValidationMessage = "A name is required.";
22 | return false;
23 | }
24 |
25 | if (string.IsNullOrEmpty(value.Email))
26 | {
27 | ValidationMessage = "A email is required.";
28 | return false;
29 | }
30 |
31 | var str = value.Email as string;
32 |
33 | Regex regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
34 | Match match = regex.Match(str);
35 |
36 | if (!match.Success)
37 | {
38 | ValidationMessage = "Email is not valid.";
39 | return false;
40 | }
41 |
42 | return true; // Yupiii !!!
43 | }
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/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/Xamarin.Forms/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/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest/ViewModels/Example3ViewModel.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 Example3ViewModel : ExtendedPropertyChanged
9 | {
10 |
11 | public Example3ViewModel()
12 | {
13 | _user = new UserValidator();
14 | }
15 |
16 | private UserValidator _user;
17 | public UserValidator User
18 | {
19 | get => _user;
20 | set => SetProperty(ref _user, value);
21 | }
22 |
23 | public bool Validate()
24 | {
25 | // Your logic goes here
26 | return User.Validate();
27 | }
28 |
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest/ViewModels/Example4ViewModel.cs:
--------------------------------------------------------------------------------
1 | using Plugin.ValidationRules.Extensions;
2 | using Plugin.ValidationRules;
3 | using ValidationRulesTest.Validations;
4 | using ValidationRulesTest.Models;
5 | using Plugin.ValidationRules.Formatters;
6 | using Xamarin.Forms;
7 | using System.Windows.Input;
8 |
9 | namespace ValidationRulesTest.ViewModels
10 | {
11 | public class Example4ViewModel : ExtendedPropertyChanged
12 | {
13 |
14 | public Example4ViewModel()
15 | {
16 | _user = new UserValidator();
17 |
18 | _user.Name.Formatter = new StringCaseFormatter(StringCases.Capitalize);
19 | _user.LastName.Formatter = new StringCaseFormatter(StringCases.Upper);
20 | }
21 |
22 | private UserValidator _user;
23 | public UserValidator User
24 | {
25 | get => _user;
26 | set => SetProperty(ref _user, value);
27 | }
28 |
29 | public ICommand FillFormCommand => new Command(ExecuteFillFormCommand);
30 |
31 | void ExecuteFillFormCommand()
32 | {
33 | User.Name.Value = "Luis";
34 | User.LastName.Value = "Matos";
35 | User.Email.Value = "luismatos@luismts.com";
36 | }
37 |
38 | public bool Validate()
39 | {
40 | // Your logic goes here
41 | MappingTest();
42 | // Your logic goes here
43 |
44 | return User.Validate();
45 | }
46 |
47 | private void MappingTest()
48 | {
49 | var stopper = new System.Diagnostics.Stopwatch();
50 | var testRuns = 1000; // 1 second
51 |
52 | stopper.Start();
53 |
54 | User modelUser = User.Map();
55 |
56 | stopper.Stop();
57 |
58 | var time1 = stopper.Elapsed.TotalMilliseconds / (double)testRuns;
59 | System.Console.WriteLine("ManualMapper: " + time1); // Elapsed time: 0.002
60 |
61 | stopper.Restart();
62 |
63 | // Extension Mapper with simple Model
64 | var extMapperUser = User.MapValidator();
65 |
66 | stopper.Stop();
67 |
68 | var time2 = stopper.Elapsed.TotalMilliseconds / (double)testRuns;
69 | System.Console.WriteLine("ExtensionMapper: " + time2); // Elapsed time: 0.013
70 | }
71 |
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest/ViewModels/Example5ViewModel.cs:
--------------------------------------------------------------------------------
1 | using Plugin.ValidationRules;
2 | using Plugin.ValidationRules.Extensions;
3 | using Plugin.ValidationRules.Rules;
4 | using System.Collections.Generic;
5 | using ValidationRulesTest.Models;
6 | using ValidationRulesTest.Validations;
7 | using EmailRule = Plugin.ValidationRules.Rules.EmailRule;
8 |
9 | namespace ValidationRulesTest.ViewModels
10 | {
11 | public class Example5ViewModel
12 | {
13 | ValidationUnit _validationUnit;
14 | UserValidator2 _testModelValidator;
15 |
16 | public Example5ViewModel()
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 = new Validatable(
29 | new NotEmptyRule("").WithMessage("A name is required."),
30 | new IsNotNullOrEmptyRule().WithMessage(() => "Hi!")
31 | );
32 |
33 | LastName = Validator.Build()
34 | .IsRequired("A last name is required.")
35 | .Must(CustomValidation, "Last name need to be longer.")
36 | .When(x => Name.Validate());
37 |
38 | //// You can add several Rules by this
39 | ///
40 | //Email = new Validatable(
41 | // new IsNotNullOrEmptyRule().WithMessage("A email is required."),
42 | // new EmailRule()
43 | //);
44 |
45 | // Or this
46 | Email = Validator.Build()
47 | //.Add(new IsNotNullOrEmptyRule(), "An email is required.")
48 | .IsRequired("An email is required.")
49 | .WithRule(new EmailRule())
50 | .When(x => Name.Validate() && LastName.Validate());
51 |
52 | // Add to the unit
53 | _validationUnit = new ValidationUnit(Name, LastName, Email);
54 |
55 | //var listValidatables = new List> { Name, LastName, Email };
56 | //_validationUnit = new ValidationUnit(listValidatables);
57 |
58 | // Validator Model
59 | _testModelValidator = new UserValidator2();
60 | }
61 |
62 | public bool Validate()
63 | {
64 | // Test model
65 | //var isValidModel = _testModelValidator.Validate();
66 |
67 | return _validationUnit.Validate();
68 | }
69 |
70 | private bool CustomValidation(string parameter)
71 | {
72 | return parameter?.Length > 3;
73 | }
74 |
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest/ViewModels/Example6ViewModel.cs:
--------------------------------------------------------------------------------
1 | using Plugin.ValidationRules;
2 | using Plugin.ValidationRules.Extensions;
3 | using Plugin.ValidationRules.Formatters;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Text;
7 |
8 | namespace ValidationRulesTest.ViewModels
9 | {
10 | public class Example6ViewModel
11 | {
12 | public Example6ViewModel()
13 | {
14 | Name = Validator.Build().IsRequired("The name is required.");
15 | Phone = Validator.Build()
16 | .When(x => !string.IsNullOrEmpty(x))
17 | .Must(x => x.Length == 12, "Minimum lenght is 12.");
18 |
19 | Phone.Formatter = new MaskFormatter("XXX-XXX-XXXX");
20 | }
21 |
22 | public Validatable Name { get; set; }
23 | public Validatable Phone { get; set; }
24 |
25 | public bool Validate()
26 | {
27 | return Name.Validate() && Phone.Validate();
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest/ViewModels/Example7ViewModel.cs:
--------------------------------------------------------------------------------
1 | using Plugin.ValidationRules;
2 | using Plugin.ValidationRules.Extensions;
3 | using Plugin.ValidationRules.Formatters;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Text;
7 | using ValidationRulesTest.Validations;
8 |
9 | namespace ValidationRulesTest.ViewModels
10 | {
11 | public class Example7ViewModel
12 | {
13 | public Example7ViewModel()
14 | {
15 | Password = Validator.Build()
16 | .IsRequired("A password is required.")
17 | .WithRule(new PasswordRule());
18 |
19 | ConfirmPassword = Validator.Build()
20 | .When(_ => !string.IsNullOrEmpty(Password.Value))
21 | .Must(x => x == Password.Value, "Password is not matching.");
22 | }
23 |
24 | public Validatable Password { get; set; }
25 | public Validatable ConfirmPassword { get; set; }
26 |
27 | public bool Validate()
28 | {
29 | return Password.Validate() && ConfirmPassword.Validate();
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest/ViewModels/Example8ViewModel.cs:
--------------------------------------------------------------------------------
1 | using Plugin.ValidationRules;
2 | using Plugin.ValidationRules.Extensions;
3 | using System.Collections.Generic;
4 |
5 | namespace ValidationRulesTest.ViewModels
6 | {
7 | public class Example8ViewModel
8 | {
9 | public Example8ViewModel()
10 | {
11 | Quantity = Validator.Build()
12 | .Must(value => value > 0, "Need to specify the quantity");
13 |
14 | var monkeyList = new List();
15 | monkeyList.Add("Baboon");
16 | monkeyList.Add("Capuchin Monkey");
17 | monkeyList.Add("Blue Monkey");
18 | monkeyList.Add("Squirrel Monkey");
19 | monkeyList.Add("Golden Lion Tamarin");
20 | monkeyList.Add("Howler Monkey");
21 | monkeyList.Add("Japanese Macaque");
22 |
23 | MonkeyList = ValidatorList.Build()
24 | .AddItemsSource(monkeyList)
25 | .IsRequired("An item is required.")
26 | .Must(value =>
27 | {
28 | if(MonkeyList.SelectedIndex == 2 && Quantity.Value < 5) // == blue monkey
29 | return false;
30 |
31 | return true;
32 | }, "Minimum quantity of this monkey is 5");
33 |
34 | UnitValidation = new ValidationUnit(Quantity, MonkeyList);
35 | }
36 |
37 | public ValidationUnit UnitValidation;
38 |
39 | public Validatable Quantity { get; set; }
40 | public ValidatableList MonkeyList { get; set; }
41 |
42 | public bool Validate()
43 | {
44 | return Quantity.Validate() && MonkeyList.Validate();
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest/Views/Example1.xaml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
12 |
13 |
18 |
22 |
23 |
28 |
32 |
33 |
38 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest/Views/Example1.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Xamarin.Forms;
3 | using ValidationRulesTest.ViewModels;
4 |
5 | namespace ValidationRulesTest
6 | {
7 | public partial class Example1 : ContentPage
8 | {
9 | Example1ViewModel _context;
10 | public Example1()
11 | {
12 | InitializeComponent();
13 |
14 | _context = new ViewModels.Example1ViewModel();
15 | BindingContext = _context;
16 | }
17 |
18 | private void Button_Clicked(object sender, EventArgs e)
19 | {
20 | var isValid = _context.Validate();
21 |
22 | if (isValid)
23 | {
24 | DisplayAlert(":)", "This form is valid", "OK");
25 | }
26 | else
27 | {
28 | DisplayAlert(":(", "This form is not valid", "OK");
29 | }
30 | }
31 |
32 | private void nameEntry_Unfocused(object sender, FocusEventArgs e)
33 | {
34 | _context.Name.Validate();
35 | }
36 |
37 | private void lastnameEntry_Unfocused(object sender, FocusEventArgs e)
38 | {
39 | _context.LastName.Validate();
40 | }
41 |
42 | private void emailEntry_Unfocused(object sender, FocusEventArgs e)
43 | {
44 | _context.Email.Validate();
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest/Views/Example2.xaml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
15 |
16 |
20 |
21 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest/Views/Example2.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Xamarin.Forms;
3 | using ValidationRulesTest.ViewModels;
4 |
5 | namespace ValidationRulesTest
6 | {
7 | public partial class Example2 : ContentPage
8 | {
9 | Example2ViewModel _context;
10 | public Example2()
11 | {
12 | InitializeComponent();
13 |
14 | _context = new Example2ViewModel();
15 | BindingContext = _context;
16 | }
17 |
18 | private void Button_Clicked(object sender, EventArgs e)
19 | {
20 | var isValid = _context.Validate();
21 |
22 | if (isValid)
23 | {
24 | DisplayAlert(":)", "This form is valid", "OK");
25 | }
26 | else
27 | {
28 | DisplayAlert(":(", $"This form is not valid. {_context.User.Error}", "OK");
29 | }
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest/Views/Example3.xaml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
16 |
20 |
21 |
26 |
30 |
31 |
36 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest/Views/Example3.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Xamarin.Forms;
3 | using ValidationRulesTest.ViewModels;
4 |
5 | namespace ValidationRulesTest
6 | {
7 | public partial class Example3 : ContentPage
8 | {
9 | Example3ViewModel _context;
10 | public Example3()
11 | {
12 | InitializeComponent();
13 |
14 | _context = new Example3ViewModel();
15 | BindingContext = _context;
16 | }
17 |
18 | private void Button_Clicked(object sender, EventArgs e)
19 | {
20 | var isValid = _context.Validate();
21 |
22 | if (isValid)
23 | {
24 | DisplayAlert(":)", "This form is valid", "OK");
25 | }
26 | else
27 | {
28 | DisplayAlert(":(", "This form is not valid", "OK");
29 | }
30 | }
31 |
32 | private void nameEntry_Unfocused(object sender, FocusEventArgs e)
33 | {
34 | _context.User.Name.Validate();
35 | }
36 |
37 | private void lastnameEntry_Unfocused(object sender, FocusEventArgs e)
38 | {
39 | _context.User.LastName.Validate();
40 | }
41 |
42 | private void emailEntry_Unfocused(object sender, FocusEventArgs e)
43 | {
44 | _context.User.Email.Validate();
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest/Views/Example4.xaml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
23 |
24 |
28 |
29 |
30 |
31 |
32 |
36 |
37 |
41 |
42 |
43 |
44 |
45 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest/Views/Example4.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Xamarin.Forms;
3 | using ValidationRulesTest.ViewModels;
4 |
5 | namespace ValidationRulesTest
6 | {
7 | public partial class Example4 : ContentPage
8 | {
9 | Example4ViewModel _context;
10 | public Example4()
11 | {
12 | InitializeComponent();
13 |
14 | _context = new Example4ViewModel();
15 | BindingContext = _context;
16 | }
17 |
18 | private void Button_Clicked(object sender, EventArgs e)
19 | {
20 | var isValid = _context.Validate();
21 |
22 | if (isValid)
23 | {
24 | DisplayAlert(":)", "This form is valid", "OK");
25 | }
26 | else
27 | {
28 | DisplayAlert(":(", "This form is not valid", "OK");
29 | }
30 | }
31 |
32 | private void Button_Clicked_1(object sender, EventArgs e)
33 | {
34 | // Test clear all 1
35 | _context.User.Name.Value = null;
36 | _context.User.LastName.Value = null;
37 | _context.User.Email.Value = null;
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest/Views/Example5.xaml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
23 |
24 |
28 |
29 |
30 |
31 |
32 |
36 |
37 |
41 |
42 |
43 |
44 |
45 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest/Views/Example5.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Xamarin.Forms;
3 | using ValidationRulesTest.ViewModels;
4 |
5 | namespace ValidationRulesTest
6 | {
7 | public partial class Example5 : ContentPage
8 | {
9 | Example5ViewModel _context;
10 | public Example5()
11 | {
12 | InitializeComponent();
13 |
14 | _context = new Example5ViewModel();
15 | BindingContext = _context;
16 | }
17 |
18 | private void Button_Clicked(object sender, EventArgs e)
19 | {
20 | var isValid = _context.Validate();
21 |
22 | if (isValid)
23 | {
24 | DisplayAlert(":)", "This form is valid", "OK");
25 | }
26 | else
27 | {
28 | DisplayAlert(":(", "This form is not valid", "OK");
29 | }
30 | }
31 |
32 | private void Button_Clicked_1(object sender, EventArgs e)
33 | {
34 | // Test clear all 1
35 | _context.Name.Value = null;
36 | _context.LastName.Value = null;
37 | _context.Email.Value = null;
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest/Views/Example6.xaml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
23 |
24 |
28 |
29 |
30 |
31 |
32 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest/Views/Example6.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using ValidationRulesTest.ViewModels;
7 | using Xamarin.Forms;
8 | using Xamarin.Forms.Xaml;
9 |
10 | namespace ValidationRulesTest.Views
11 | {
12 | [XamlCompilation(XamlCompilationOptions.Compile)]
13 | public partial class Example6 : ContentPage
14 | {
15 | Example6ViewModel _context;
16 | public Example6 ()
17 | {
18 | InitializeComponent ();
19 |
20 | _context = new Example6ViewModel();
21 | BindingContext = _context;
22 | }
23 |
24 | private void Button_Clicked(object sender, EventArgs e)
25 | {
26 | var isValid = _context.Validate();
27 |
28 | if (isValid)
29 | {
30 | DisplayAlert(":)", "This form is valid", "OK");
31 | }
32 | else
33 | {
34 | DisplayAlert(":(", "This form is not valid", "OK");
35 | }
36 | }
37 | }
38 | }
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest/Views/Example7.xaml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
12 |
17 |
18 |
19 |
20 |
21 |
25 |
26 |
31 |
32 |
33 |
34 |
35 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest/Views/Example7.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using ValidationRulesTest.ViewModels;
7 | using Xamarin.Forms;
8 | using Xamarin.Forms.Xaml;
9 |
10 | namespace ValidationRulesTest.Views
11 | {
12 | [XamlCompilation(XamlCompilationOptions.Compile)]
13 | public partial class Example7 : ContentPage
14 | {
15 | Example7ViewModel _context;
16 | public Example7()
17 | {
18 | InitializeComponent();
19 |
20 | _context = new Example7ViewModel();
21 | BindingContext = _context;
22 | }
23 |
24 | private void Button_Clicked(object sender, EventArgs e)
25 | {
26 | var isValid = _context.Validate();
27 |
28 | if (isValid)
29 | {
30 | DisplayAlert(":)", "This form is valid", "OK");
31 | }
32 | else
33 | {
34 | DisplayAlert(":(", "This form is not valid", "OK");
35 | }
36 | }
37 | }
38 | }
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest/Views/Example8.xaml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
12 |
16 |
17 |
18 |
19 |
20 |
24 |
25 |
29 |
30 |
31 |
32 |
33 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest/Views/Example8.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using ValidationRulesTest.ViewModels;
3 | using Xamarin.Forms;
4 | using Xamarin.Forms.Xaml;
5 |
6 | namespace ValidationRulesTest.Views
7 | {
8 | [XamlCompilation(XamlCompilationOptions.Compile)]
9 | public partial class Example8 : ContentPage
10 | {
11 | Example8ViewModel _context;
12 | public Example8()
13 | {
14 | try
15 | {
16 | InitializeComponent();
17 |
18 | _context = new Example8ViewModel();
19 | BindingContext = _context;
20 | }
21 | catch (Exception e)
22 | {
23 |
24 | throw;
25 | }
26 | }
27 |
28 | private void Button_Clicked(object sender, EventArgs e)
29 | {
30 | //var isValid = _context.Validate();
31 | var isValid = _context.UnitValidation.Validate();
32 |
33 | if (isValid)
34 | {
35 | DisplayAlert(":)", "This form is valid", "OK");
36 | }
37 | else
38 | {
39 | var error = _context.UnitValidation.Error;
40 | DisplayAlert(":(", error, "OK");
41 | }
42 | }
43 | }
44 | }
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest/Views/Examples.xaml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
17 |
18 |
22 |
26 |
30 |
34 |
35 |
39 |
40 |
44 |
45 |
49 |
50 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/samples/Xamarin.Forms/ValidationRulesTest/ValidationRulesTest/Views/Examples.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | using Xamarin.Forms;
8 | using Xamarin.Forms.Xaml;
9 |
10 | namespace ValidationRulesTest.Views
11 | {
12 | [XamlCompilation(XamlCompilationOptions.Compile)]
13 | public partial class Examples : ContentPage
14 | {
15 | public Examples()
16 | {
17 | InitializeComponent();
18 | }
19 |
20 | private void example1_Clicked(object sender, EventArgs e)
21 | {
22 | Navigation.PushAsync(new Example1());
23 | }
24 |
25 | private void example2_Clicked(object sender, EventArgs e)
26 | {
27 | Navigation.PushAsync(new Example2());
28 | }
29 |
30 | private void example3_Clicked(object sender, EventArgs e)
31 | {
32 | Navigation.PushAsync(new Example3());
33 | }
34 |
35 | private void example4_Clicked(object sender, EventArgs e)
36 | {
37 | Navigation.PushAsync(new Example4());
38 | }
39 |
40 | private void example5_Clicked(object sender, EventArgs e)
41 | {
42 | Navigation.PushAsync(new Example5());
43 | }
44 |
45 | private void example6_Clicked(object sender, EventArgs e)
46 | {
47 | Navigation.PushAsync(new Example6());
48 | }
49 |
50 | private void example7_Clicked(object sender, EventArgs e)
51 | {
52 | Navigation.PushAsync(new Example7());
53 | }
54 |
55 | private void example8_Clicked(object sender, EventArgs e)
56 | {
57 | Navigation.PushAsync(new Example8());
58 | }
59 | }
60 | }
--------------------------------------------------------------------------------
/src/ValidationRules/Extensions/ExtendedPropertyChanged.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.ComponentModel;
3 | using System.Runtime.CompilerServices;
4 |
5 | namespace Plugin.ValidationRules.Extensions
6 | {
7 | ///
8 | /// Notifies clients that a property value has changed
9 | ///
10 | public abstract class ExtendedPropertyChanged : INotifyPropertyChanged
11 | {
12 | ///
13 | /// Occurs when a property value changes.
14 | ///
15 | public event PropertyChangedEventHandler PropertyChanged;
16 |
17 | ///
18 | /// Notifies clients that a property value has changed
19 | ///
20 | protected virtual void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
21 | {
22 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
23 | }
24 |
25 | ///
26 | /// Assign a new value
27 | ///
28 | ///
29 | ///
30 | ///
31 | ///
32 | ///
33 | protected bool SetProperty(ref T storage, T value, [CallerMemberName]string propertyName = null)
34 | {
35 | if (EqualityComparer.Default.Equals(storage, value))
36 | {
37 | return false;
38 | }
39 |
40 | storage = value;
41 | NotifyPropertyChanged(propertyName);
42 |
43 | return true;
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/ValidationRules/Extensions/Extensions.cs:
--------------------------------------------------------------------------------
1 | using Plugin.ValidationRules.Interfaces;
2 | using System;
3 | using System.Linq;
4 | using System.Reflection;
5 |
6 | namespace Plugin.ValidationRules.Extensions
7 | {
8 | public static class Extensions
9 | {
10 | ///
11 | /// Capitalize the first character and add a space before each capitalized letter (except the first character).
12 | ///
13 | ///
14 | ///
15 | public static string ToCapitalizeCase(this string the_string)
16 | {
17 | // If there are 0 or 1 characters, just return the string.
18 | if (the_string == null) return the_string;
19 | if (the_string.Length < 2) return the_string.ToUpper();
20 |
21 | // Start with the first character.
22 | string result = the_string.Substring(0, 1).ToUpper();
23 |
24 | // Add the remaining characters.
25 | for (int i = 1; i < the_string.Length; i++)
26 | {
27 | if (char.IsUpper(the_string[i])) result += " ";
28 | result += the_string[i];
29 | }
30 |
31 | return result;
32 | }
33 |
34 | public static Model MapValidator(this Validator validator) where Model : new()
35 | {
36 | if (validator == null)
37 | return default(Model);
38 |
39 | Model newModel = new Model();
40 |
41 | Type modelObjectType = newModel.GetType();
42 | PropertyInfo[] modelPropList = modelObjectType.GetProperties();
43 |
44 | Type validatorType = validator.GetType();
45 | PropertyInfo[] validatorPropList = validatorType.GetProperties();
46 |
47 | foreach (PropertyInfo validatorPropInfo in validatorPropList)
48 | {
49 | foreach (PropertyInfo modelPropInfo in modelPropList)
50 | {
51 | if (modelPropInfo.Name == validatorPropInfo.Name)
52 | {
53 | try
54 | {
55 | PropertyInfo validatorProp = validatorPropInfo.PropertyType.GetProperty(nameof(Validatable.Value));
56 |
57 | if (validatorProp == null)
58 | break;
59 |
60 | var validatorPropValue = validatorPropInfo.GetValue(validator); // Not working directly
61 | var propValue = validatorProp.GetValue(validatorPropValue, null);
62 |
63 | modelPropInfo.SetValue(newModel, propValue, null);
64 | }
65 | catch (Exception) { }
66 |
67 | break;
68 | }
69 | }
70 | }
71 |
72 | return newModel;
73 | }
74 |
75 | public static IValidationRule WithMessage(this IValidationRule rule, string message)
76 | {
77 | if(message?.Length > 0)
78 | rule.ValidationMessage = message;
79 |
80 | return rule;
81 | }
82 |
83 | public static IValidationRule WithMessage(this IValidationRule rule, Func messageProvider)
84 | {
85 | var message = messageProvider();
86 |
87 | if (message?.Length > 0)
88 | rule.ValidationMessage = message;
89 |
90 | return rule;
91 | }
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/src/ValidationRules/Extensions/RelayCommand.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Input;
3 |
4 | namespace Plugin.ValidationRules.Extensions
5 | {
6 | public class RelayCommand : ICommand
7 | {
8 | readonly Func