using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
namespace Holworth.Utility
{
public class ValidateCommon
{
public static bool ValidateDaysConvention(string a)
{
if (a.ToLower() == "A/360".ToLower() || a.ToLower() == "A/365".ToLower() || a.ToLower() == "ACTUAL/360".ToLower() || a.ToLower() == "ACTUAL/365".ToLower() || a.ToLower() == "Act/360".ToLower() || a.ToLower() == "Act/365".ToLower())
{
return true;
}
return false;
}
public static bool ValidateRateDayCountFraction(string a)
{
if (a.ToLower() == "Act/360,Ajusted".ToLower() || a.ToLower() == "Act/365,Ajusted")
{
return true;
}
return false;
}
public static bool ValidateBenchmarkInterest(string a)
{
if (a.ToLower() == "A/360".ToLower() || a.ToLower() == "A/365".ToLower() || a.ToLower() == "ACTUAL/360".ToLower() || a.ToLower() == "ACTUAL/365".ToLower() || a.ToLower() == "Act/360".ToLower() || a.ToLower() == "Act/365".ToLower())
{
return true;
}
return false;
}
public static bool ValidateCCYPair(string a)
{
string regexPosition = @"^[A-Z]{3}\.[A-Z]{3}$";
if (Regex.IsMatch(a, regexPosition))
{
return true;
}
return false;
}
public static bool ValidateNotionCurrency(string a)
{
string regexPositio2 = @"^([A-Z]{3}/[A-Z]{3})|([A-Z]{3})$";
if (Regex.IsMatch(a, regexPositio2))
{
return true;
}
return false;
}
public static bool ValidateBuyOrSell(string a)
{
if (a.ToUpper() == "BUY" || a.ToUpper() == "SELL"||a=="买"||a=="卖")
{
return true;
}
return false;
}
public static bool ValidateCallOrPut(string a)
{
if (a.ToUpper() == "Call".ToUpper() || a.ToUpper() == "Put".ToUpper())
{
return true;
}
return false;
}
public static bool ValidateCCYBaseDirection(string a)
{
if (a.ToUpper() == "B" || a.ToUpper() == "S" || a.ToUpper() == "Buy" || a.ToUpper() == "Sell"||a.ToUpper()=="B/S")
{
return true;
}
return false;
}
public static bool ValidatePrice(string a)
{
string regexPosition = @"^([0-9]+(\.[0-9]+)?)$";
if (Regex.IsMatch(a, regexPosition))
{
return true;
}
else
{
return false;
}
}
public static bool ValidateIsNum(string a)
{
string regexPosition = @"^([0-9]+)$";
if (Regex.IsMatch(a, regexPosition))
{
return true;
}
else
{
return false;
}
}
public static bool ValidateDateTime(string date)
{
date = date.Replace("‘", "");
string RegexExpression =
@"^(\d{4}-(?:0?\d|1[0-2])-(?:[0-2]?\d|3[01])( (?:[01]\d|2[0-3])\:[0-5]\d\:[0-5]\d)?)|(\d{4}/(?:0?\d|1[0-2])/(?:[0-2]?\d|3[01])( (?:[01]\d|2[0-3])\:[0-5]\d\:[0-5]\d)?)|((?:0[1-9]|[12][0-9]|3[01])\/(?:0[1-9]|1[0-2])\/((?:19|20)\d{2})( (?:[01]\d|2[0-3])\:[0-5]\d\:[0-5]\d)?)|((19|20)\d\d(0[1-9]|1[012])(0[1-9]|[12]\d|3[01]))$";
if (Regex.IsMatch(date, RegexExpression))
{
return true;
}
return false;
}
/// <summary>
/// 时间转换yyyy/mm/dd格式
/// </summary>
/// <param name="date"></param>
/// <returns></returns>
public static string ValidateDateTimeString(string date)
{
date = date.Replace("‘", "");
string RegexExpression = @"^(19|20)\d\d(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])$";
if (Regex.IsMatch(date, RegexExpression))
{
string dateTime = date;
string year = dateTime.Substring(0, 4);
string mm = dateTime.Substring(4, 2);
string dd = dateTime.Substring(6, 2);
return date = year + "/" + mm + "/" + dd;
}
return date;
}
public static bool ValidateNotNull(string a)
{
if (!string.IsNullOrEmpty(a))
{
return true;
}
return false;
}
public static bool ValidateValuationCurreny(string a)
{
string regexPosition = @"^[A-Z]{3}$";
if (Regex.IsMatch(a, regexPosition))
{
return true;
}
else
{
return false;
}
return false;
}
public static bool ValidateCurreny(string a)
{
string regexPosition = @"^[A-Z]{3}$";
if (Regex.IsMatch(a, regexPosition))
{
return true;
}
else
{
return false;
}
return false;
}
public static bool ValidateCCYAmount(string amount)
{
amount = amount.Replace(",", "");
string regexPosition = @"^([0-9]+(\.[0-9]+)?)$";
if (Regex.IsMatch(amount, regexPosition))
{
return true;
}
else
{
return false;
}
}
}
}