Removed unused functions and documented reporting
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user