-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #249 from MADE-Apps/feature/new-validators
Added collection of new data validators
- Loading branch information
Showing
21 changed files
with
1,101 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// MADE Apps licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
namespace MADE.Data.Validation.Validators | ||
{ | ||
using System.Text.RegularExpressions; | ||
using MADE.Data.Validation.Extensions; | ||
using MADE.Data.Validation.Strings; | ||
|
||
/// <summary> | ||
/// Defines a data validator for ensuring a value is a valid base64 value. | ||
/// </summary> | ||
public class Base64Validator : RegexValidator | ||
{ | ||
private string feedbackMessage; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="Base64Validator"/> class. | ||
/// </summary> | ||
public Base64Validator() | ||
{ | ||
this.Key = nameof(Base64Validator); | ||
this.Pattern = @"^[a-zA-Z0-9\+/]*={0,3}$"; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the feedback message to display when <see cref="IValidator.IsInvalid"/> is true. | ||
/// </summary> | ||
public override string FeedbackMessage | ||
{ | ||
get => this.feedbackMessage.IsNullOrWhiteSpace() | ||
? Resources.Base64Validator_FeedbackMessage | ||
: this.feedbackMessage; | ||
set => this.feedbackMessage = value; | ||
} | ||
|
||
/// <summary> | ||
/// Executes data validation on the provided <paramref name="value"/>. | ||
/// </summary> | ||
/// <param name="value">The value to be validated.</param> | ||
/// <exception cref="RegexMatchTimeoutException">Thrown if a Regex time-out occurred.</exception> | ||
public override void Validate(object value) | ||
{ | ||
var stringValue = value?.ToString() ?? string.Empty; | ||
if (stringValue.Length % 4 != 0) | ||
{ | ||
this.IsInvalid = true; | ||
} | ||
else | ||
{ | ||
base.Validate(value); | ||
} | ||
|
||
this.IsDirty = true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.