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;
    }
    }

    }
    }

  • 相关阅读:
    网上找的Backbone.js
    关于数据结构,剑指offer上面的
    软件工程 什么叫高内聚 低耦合
    【丢失的转化率】你的宝贝,有多少人放进了购物车却没有支付?
    怎么都没人提 google 加密搜索呢? google如何稳定打开
    Mustache.js语法学习笔记
    C# POST数据到指定页面,并跳转至该页面
    将多个图片整合到一张图片中再用CSS 进行网页背景定位
    铁通、长宽网络支付时“签名失败”问题分析及解决方案  [88222001]验证签名异常:FAIL[20131101100002-142]
    jqGrid中多选
  • 原文地址:https://www.cnblogs.com/kexb/p/4800811.html
Copyright © 2011-2022 走看看