zoukankan      html  css  js  c++  java
  • c# 常规验证基类

    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)dd(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)dd(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;
    }
    }

    }
    }

  • 相关阅读:
    一些有关时间的获取
    Devexpress xaf用代码打开菜单(Navigation Item)
    Devexpress xaf BO中字段为RuleRequiredField必输字段时,文本标签默认添加*标记
    Devepxress xaf Dashboard中DetailView控件使其可编辑
    Devexpress WinForm TreeList的三种数据绑定方式(DataSource绑定、AppendNode添加节点、VirtualTreeGetChildNodes(虚拟树加载模式))
    Devexpress xaf针对某个用户登录后在面板中设置导航无效的解决方法
    IIS不能下载config配置文件的解决方法
    DevExpress WPF控件记录
    Devexpress WinForm GridControl实现单元格可编辑状态更改
    Devexpress GridControl中 repositoryItemCheckEdit作为选择列以及作为显示列的使用方法
  • 原文地址:https://www.cnblogs.com/kexb/p/4800811.html
Copyright © 2011-2022 走看看