C # General validation base class

Source: Internet
Author: User

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== "Buy" | | a== "sell")
{
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.ISMATC H (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>
Time Conversion YYYY/MM/DD format
</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;
}
}

}
}

C # General validation base class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.