aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Models/Validation/UsernameValidator.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-02-02 14:35:30 +0800
committercrupest <crupest@outlook.com>2020-02-02 14:35:30 +0800
commitcb18564275735da0614be39371e2e3e7f5467e88 (patch)
tree06388f533584b06a185c5908603423af158f671a /Timeline/Models/Validation/UsernameValidator.cs
parent9e84b1e9ad1f2a45cd3e09759c69989fdc588c3d (diff)
downloadtimeline-cb18564275735da0614be39371e2e3e7f5467e88.tar.gz
timeline-cb18564275735da0614be39371e2e3e7f5467e88.tar.bz2
timeline-cb18564275735da0614be39371e2e3e7f5467e88.zip
Add timeline service.
Diffstat (limited to 'Timeline/Models/Validation/UsernameValidator.cs')
-rw-r--r--Timeline/Models/Validation/UsernameValidator.cs28
1 files changed, 1 insertions, 27 deletions
diff --git a/Timeline/Models/Validation/UsernameValidator.cs b/Timeline/Models/Validation/UsernameValidator.cs
index d8f3bdc0..87bbf85f 100644
--- a/Timeline/Models/Validation/UsernameValidator.cs
+++ b/Timeline/Models/Validation/UsernameValidator.cs
@@ -1,35 +1,9 @@
using System;
-using System.Linq;
-using static Timeline.Resources.Models.Validation.UsernameValidator;
namespace Timeline.Models.Validation
{
- public class UsernameValidator : Validator<string>
+ public class UsernameValidator : NameValidator
{
- public const int MaxLength = 26;
-
- protected override (bool, string) DoValidate(string value)
- {
- if (value.Length == 0)
- {
- return (false, MessageEmptyString);
- }
-
- if (value.Length > 26)
- {
- return (false, MessageTooLong);
- }
-
- foreach ((char c, int i) in value.Select((c, i) => (c, i)))
- {
- if (!(char.IsLetterOrDigit(c) || c == '-' || c == '_'))
- {
- return (false, MessageInvalidChar);
- }
- }
-
- return (true, GetSuccessMessage());
- }
}
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter,