aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Models/Validation/UserDetailValidator.cs
diff options
context:
space:
mode:
author杨宇千 <crupest@outlook.com>2019-10-21 20:47:31 +0800
committer杨宇千 <crupest@outlook.com>2019-10-21 20:47:31 +0800
commitc442b7ad597f430b186dd8019de70332b574c4ba (patch)
treee6a9d4204e4fcd047cfcf5acd4ff566cf8bb69ff /Timeline/Models/Validation/UserDetailValidator.cs
parent4c52f2d8b7aae43f391f54fb67fe91b8bc64e0c5 (diff)
downloadtimeline-c442b7ad597f430b186dd8019de70332b574c4ba.tar.gz
timeline-c442b7ad597f430b186dd8019de70332b574c4ba.tar.bz2
timeline-c442b7ad597f430b186dd8019de70332b574c4ba.zip
...
Diffstat (limited to 'Timeline/Models/Validation/UserDetailValidator.cs')
-rw-r--r--Timeline/Models/Validation/UserDetailValidator.cs116
1 files changed, 0 insertions, 116 deletions
diff --git a/Timeline/Models/Validation/UserDetailValidator.cs b/Timeline/Models/Validation/UserDetailValidator.cs
deleted file mode 100644
index 19c82edb..00000000
--- a/Timeline/Models/Validation/UserDetailValidator.cs
+++ /dev/null
@@ -1,116 +0,0 @@
-using System;
-using System.Net.Mail;
-
-namespace Timeline.Models.Validation
-{
- public abstract class OptionalStringValidator : IValidator
- {
- public bool Validate(object value, out string message)
- {
- if (value == null)
- {
- message = ValidationConstants.SuccessMessage;
- return true;
- }
-
- if (value is string s)
- {
- if (s.Length == 0)
- {
- message = ValidationConstants.SuccessMessage;
- return true;
- }
- return DoValidate(s, out message);
- }
- else
- {
- message = "Value is not of type string.";
- return false;
- }
- }
-
- protected abstract bool DoValidate(string value, out string message);
- }
-
- public static class UserDetailValidators
- {
-
- public class QQValidator : OptionalStringValidator
- {
- protected override bool DoValidate(string value, out string message)
- {
- if (value.Length < 5)
- {
- message = "QQ is too short.";
- return false;
- }
-
- if (value.Length > 11)
- {
- message = "QQ is too long.";
- return false;
- }
-
- foreach (var c in value)
- {
- if (!char.IsDigit(c))
- {
- message = "QQ must only contain digit.";
- return false;
- }
- }
-
- message = ValidationConstants.SuccessMessage;
- return true;
- }
- }
-
- public class EMailValidator : OptionalStringValidator
- {
- protected override bool DoValidate(string value, out string message)
- {
- if (value.Length > 50)
- {
- message = "E-Mail is too long.";
- return false;
- }
-
- try
- {
- var _ = new MailAddress(value);
- }
- catch (FormatException)
- {
- message = "The format of E-Mail is bad.";
- return false;
- }
- message = ValidationConstants.SuccessMessage;
- return true;
- }
- }
-
- public class PhoneNumberValidator : OptionalStringValidator
- {
- protected override bool DoValidate(string value, out string message)
- {
- if (value.Length > 14)
- {
- message = "Phone number is too long.";
- return false;
- }
-
- foreach (var c in value)
- {
- if (!char.IsDigit(c))
- {
- message = "Phone number can only contain digit.";
- return false;
- }
- }
-
- message = ValidationConstants.SuccessMessage;
- return true;
- }
- }
- }
-}