init backend
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
using AipsCore.Domain.Abstract;
|
||||
using AipsCore.Domain.Abstract.Rule;
|
||||
|
||||
namespace AipsCore.Domain.Common.Validation.Rules;
|
||||
|
||||
public class CharsetRule : AbstractRule
|
||||
{
|
||||
private readonly string _stringValue;
|
||||
private readonly char[] _charset;
|
||||
|
||||
protected CharsetRule(string stringValue, char[] charset)
|
||||
{
|
||||
_stringValue = stringValue;
|
||||
_charset = charset;
|
||||
}
|
||||
|
||||
protected override string ErrorCode => "charset";
|
||||
protected override string ErrorMessage => $"Forbidden characters in '{ValueObjectName}'";
|
||||
|
||||
public override bool Validate()
|
||||
{
|
||||
foreach (char character in _stringValue)
|
||||
{
|
||||
if (!_charset.Contains(character))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
32
dotnet/AipsCore/Domain/Common/Validation/Rules/EmailRule.cs
Normal file
32
dotnet/AipsCore/Domain/Common/Validation/Rules/EmailRule.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System.Net.Mail;
|
||||
using AipsCore.Domain.Abstract;
|
||||
using AipsCore.Domain.Abstract.Rule;
|
||||
|
||||
namespace AipsCore.Domain.Common.Validation.Rules;
|
||||
|
||||
public class EmailRule : AbstractRule
|
||||
{
|
||||
protected override string ErrorCode => "email_invalid";
|
||||
protected override string ErrorMessage => "Email is not in the valid format";
|
||||
|
||||
private readonly string _emailValue;
|
||||
|
||||
public EmailRule(string emailValue)
|
||||
{
|
||||
_emailValue = emailValue;
|
||||
}
|
||||
|
||||
public override bool Validate()
|
||||
{
|
||||
try
|
||||
{
|
||||
_ = new MailAddress(_emailValue);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using AipsCore.Domain.Abstract;
|
||||
using AipsCore.Domain.Abstract.Rule;
|
||||
|
||||
namespace AipsCore.Domain.Common.Validation.Rules;
|
||||
|
||||
public class ExactLength : AbstractRule
|
||||
{
|
||||
private readonly string _stringValue;
|
||||
private readonly int _exactLentgh;
|
||||
protected override string ErrorCode => "exact_length";
|
||||
protected override string ErrorMessage
|
||||
=> $"Length of '{ValueObjectName}' must be {_exactLentgh} characters";
|
||||
|
||||
public ExactLength(string stringValue, int exactLentgh)
|
||||
{
|
||||
_stringValue = stringValue;
|
||||
_exactLentgh = exactLentgh;
|
||||
}
|
||||
|
||||
public override bool Validate()
|
||||
{
|
||||
return _stringValue.Length == _exactLentgh;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using AipsCore.Domain.Abstract;
|
||||
using AipsCore.Domain.Abstract.Rule;
|
||||
|
||||
namespace AipsCore.Domain.Common.Validation.Rules;
|
||||
|
||||
public class MaxLengthRule : AbstractRule
|
||||
{
|
||||
private readonly string _stringValue;
|
||||
private readonly int _maximumLentgh;
|
||||
protected override string ErrorCode => "minimum_length";
|
||||
protected override string ErrorMessage
|
||||
=> $"Length of '{ValueObjectName}' must be at most {_maximumLentgh} characters";
|
||||
|
||||
public MaxLengthRule(string stringValue, int maximumLentgh)
|
||||
{
|
||||
_stringValue = stringValue;
|
||||
_maximumLentgh = maximumLentgh;
|
||||
}
|
||||
|
||||
public override bool Validate()
|
||||
{
|
||||
return _stringValue.Length <= _maximumLentgh;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using AipsCore.Domain.Abstract;
|
||||
using AipsCore.Domain.Abstract.Rule;
|
||||
|
||||
namespace AipsCore.Domain.Common.Validation.Rules;
|
||||
|
||||
public class MinLengthRule : AbstractRule
|
||||
{
|
||||
private readonly string _stringValue;
|
||||
private readonly int _minimumLentgh;
|
||||
protected override string ErrorCode => "minimum_length";
|
||||
protected override string ErrorMessage
|
||||
=> $"Length of '{ValueObjectName}' must be at least {_minimumLentgh} characters";
|
||||
|
||||
public MinLengthRule(string stringValue, int minimumLentgh)
|
||||
{
|
||||
_stringValue = stringValue;
|
||||
_minimumLentgh = minimumLentgh;
|
||||
}
|
||||
|
||||
public override bool Validate()
|
||||
{
|
||||
return _stringValue.Length >= _minimumLentgh;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user