Removed unused functions and documented reporting

This commit is contained in:
雲華
2022-04-17 13:19:35 -04:00
parent f6f90c76b2
commit 565997b9d7
5 changed files with 99 additions and 34 deletions

View File

@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.Text.RegularExpressions;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
@@ -11,46 +6,56 @@ namespace Ophelias.Expressions
{
internal static class Expressions
{
/*
* These are a collection of regular expressions used in the validation class.
* They exist in their own class to better isolate them and make it easier to
* find.
*
* CardRx
* Regular expression to check for 16 digit credit cards
*
* ExpirationRx
* Ensures that a card expires sometime in past 2021
*
* CCVRx
* Checks to make sure the input is 3 digits
*
* MoneyRx
* Basic check to make sure money is in US format. 300.20/ 0.00 etc.
*/
internal static Regex CardRx = new(@"^[0-9]{16}$", RegexOptions.Compiled);
internal static Regex ExpriationRx = new(@"^(0?[1-9]|1[012])/2[0-9]{1}$", RegexOptions.Compiled);
internal static Regex ExpriationRx = new(@"^(0?[1-9]|1[012])/[2-9][0-9]{1}$", RegexOptions.Compiled);
internal static Regex CCVRx = new(@"^[0-9]{3}$", RegexOptions.Compiled);
internal static Regex MoneyRx = new(@"^(\d+\.\d{2}|\d+)$", RegexOptions.Compiled);
}
internal static class Validation
{
internal static bool ValidateCreditCard(string CreditCard)
internal static bool ValidateCreditCard(string CreditCard) // Returns if the regex evaluates true or false
{
return Expressions.CardRx.IsMatch(CreditCard);
}
internal static bool ValidateExpirationDate(string Expiration)
internal static bool ValidateExpirationDate(string Expiration) // Returns if the regex evaluates true or false
{
if (Expressions.ExpriationRx.IsMatch(Expiration))
{
DateTime dt = DateTime.ParseExact(Expiration, "MM/yy", CultureInfo.InvariantCulture);
DateTime dt = DateTime.ParseExact(Expiration, "MM/yy", CultureInfo.InvariantCulture); // Converts to date time for comparison
if (dt.Date >= DateTime.Now.Date)
return true;
}
return false;
}
internal static bool ValidateExpirationNotBeforeReservation(string Expiration, DateTime CollectionDate)
internal static bool ValidateEmail(string email) // Returns if the regex evaluates true or false
{
DateTime dt = DateTime.ParseExact(Expiration, "MM/yy", CultureInfo.InvariantCulture);
if (dt.Date > CollectionDate.Date)
return true;
return false;
}
internal static bool ValidateEmail(string email)
{
EmailAddressAttribute EmailChecker = new();
EmailAddressAttribute EmailChecker = new(); // Creates an email checker based off the EmailAddressAttribute class
return EmailChecker.IsValid(email);
}
internal static bool ValidateCCV(string CCV)
internal static bool ValidateCCV(string CCV) // Returns if the regex evaluates true or false
{
if (Expressions.CCVRx.IsMatch(CCV))
return true;
return false;
}
internal static bool ValidateMoney(string Money)
internal static bool ValidateMoney(string Money) // Returns if the regex evaluates true or false
{
return Expressions.MoneyRx.IsMatch(Money);
}