You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

214 lines
6.1 KiB

namespace com.hitrust.trustpay.client
{
using System;
public class DataVerifier
{
public static bool isValidAmount(string sAmount)
{
if (sAmount == null)
{
return false;
}
return (sAmount.IndexOf('.') >= (sAmount.Length - 3));
}
public static bool isValidAmount(double aAmount, int aExp)
{
bool tResult = false;
if (aExp >= 0)
{
string tAmountStr = aAmount.ToString();
int tIndex = tAmountStr.IndexOf('.');
if (tIndex == -1)
{
return true;
}
if (tIndex >= ((tAmountStr.Length - aExp) - 1))
{
tResult = true;
}
}
return tResult;
}
public static bool isValidDate(string aString)
{
bool tResult = false;
if (aString.Length != 10)
{
return false;
}
if ((aString[4] != '/') || (aString[7] != '/'))
{
return false;
}
try
{
int tYYYY = int.Parse(aString.Substring(0, 4));
int tMM = int.Parse(aString.Substring(5, 2));
int tDD = int.Parse(aString.Substring(8, 2));
if ((tMM < 1) || (tMM > 12))
{
return false;
}
if ((tDD < 1) || (tDD > 0x1f))
{
return false;
}
tResult = true;
}
catch (Exception e)
{
Console.Out.WriteLine(e);
}
return tResult;
}
public static bool isValidDate8(string sDate)
{
bool tResult = false;
if (sDate == null)
{
return false;
}
if (sDate.Length != 8)
{
return false;
}
try
{
int tYYYY = int.Parse(sDate.Substring(0, 4));
int tMM = int.Parse(sDate.Substring(4, 2));
int tDD = int.Parse(sDate.Substring(6, 2));
if ((tMM < 1) || (tMM > 12))
{
return false;
}
if ((tDD < 1) || (tDD > 0x1f))
{
return false;
}
if ((((tMM == 4) || (tMM == 6)) || ((tMM == 9) || (tMM == 11))) && (tDD > 30))
{
return false;
}
if (tMM == 2)
{
if ((((tYYYY % 4) == 0) && ((tYYYY % 100) != 0)) || ((tYYYY % 400) == 0))
{
if (tDD > 0x1d)
{
return false;
}
}
else if (tDD > 0x1c)
{
return false;
}
}
tResult = true;
}
catch (Exception)
{
return false;
}
return tResult;
}
public static bool isValidTime(string aString)
{
bool tResult = false;
if (aString.Length != 8)
{
return false;
}
if ((aString[2] != ':') || (aString[5] != ':'))
{
return false;
}
try
{
int tHH = int.Parse(aString.Substring(0, 2));
int tMM = int.Parse(aString.Substring(3, 2));
int tSS = int.Parse(aString.Substring(6, 2));
if ((tHH < 0) || (tHH > 0x17))
{
return false;
}
if ((tMM < 0) || (tMM > 0x3b))
{
return false;
}
if ((tSS < 0) || (tSS > 0x3b))
{
return false;
}
tResult = true;
}
catch (Exception)
{
}
return tResult;
}
public static bool isValidTime6(string sTime)
{
if (sTime == null)
{
return false;
}
if (sTime.Length != 6)
{
return false;
}
try
{
int tHH = int.Parse(sTime.Substring(0, 2));
int tMM = int.Parse(sTime.Substring(2, 2));
int tSS = int.Parse(sTime.Substring(4, 2));
if ((tHH < 0) || (tHH > 0x17))
{
return false;
}
if ((tMM < 0) || (tMM > 0x3b))
{
return false;
}
if ((tSS < 0) || (tSS > 0x3b))
{
return false;
}
}
catch (Exception)
{
return false;
}
return true;
}
public static bool isValidURL(string aString)
{
if (aString.Length < 20)
{
return false;
}
if ((aString.IndexOf("http://") != 0) && (aString.IndexOf("https://") != 0))
{
return false;
}
return true;
}
[STAThread]
public static void Main(string[] argc)
{
for (int i = 0; i <= 200; i++)
{
string tAmountStr = "100." + i;
Console.Out.WriteLine(string.Concat(new object[] { "Amount = [", tAmountStr, "]\tResult = [", isValidAmount((double) float.Parse(tAmountStr), 2), "]" }));
}
}
}
}