aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Models
diff options
context:
space:
mode:
Diffstat (limited to 'Timeline/Models')
-rw-r--r--Timeline/Models/Validation/NameValidator.cs33
-rw-r--r--Timeline/Models/Validation/TimelineNameValidator.cs19
-rw-r--r--Timeline/Models/Validation/UsernameValidator.cs28
3 files changed, 53 insertions, 27 deletions
diff --git a/Timeline/Models/Validation/NameValidator.cs b/Timeline/Models/Validation/NameValidator.cs
new file mode 100644
index 00000000..8db10ebd
--- /dev/null
+++ b/Timeline/Models/Validation/NameValidator.cs
@@ -0,0 +1,33 @@
+using System.Linq;
+using static Timeline.Resources.Models.Validation.NameValidator;
+
+namespace Timeline.Models.Validation
+{
+ public class NameValidator : Validator<string>
+ {
+ 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());
+ }
+ }
+}
diff --git a/Timeline/Models/Validation/TimelineNameValidator.cs b/Timeline/Models/Validation/TimelineNameValidator.cs
new file mode 100644
index 00000000..f1ab54e8
--- /dev/null
+++ b/Timeline/Models/Validation/TimelineNameValidator.cs
@@ -0,0 +1,19 @@
+using System;
+
+namespace Timeline.Models.Validation
+{
+ public class TimelineNameValidator : NameValidator
+ {
+ }
+
+ [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter,
+ AllowMultiple = false)]
+ public class TimelineNameAttribute : ValidateWithAttribute
+ {
+ public TimelineNameAttribute()
+ : base(typeof(TimelineNameValidator))
+ {
+
+ }
+ }
+}
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,