IsValidExpiration方法中的当前上下文中不存在txt_ExpirationDate

时间:2018-07-23 10:29:42

标签: c# visual-studio

{
    Random r = new Random();
    int a = r.Next(1000000000);
    string  Expirydate = txt_ExpirationDate.Text;

    if (CryptoEngine.IsValidExpiration(Expirydate) == false)
    {
        Response.Write("<script>alert('Expiry Date not valid');</script>");
    }

public bool IsValidExpiration(string ExpiryDate)
{
    string[] date = Regex.Split(txt_ExpirationDate.Text, "/");
    string[] currentDate = Regex.Split(DateTime.Now.ToString("MM/yyyy"), "/");
    int compareYears = string.Compare(date[1], currentDate[1]);
    int compareMonths = string.Compare(date[0], currentDate[0]);

    //if expiration date is in MM/YYYY format
    if (Regex.Match(txt_ExpirationDate.Text, @"^\d{2}/\d{4}$").Success)
    {
        //if month is "01-12" and year starts with "20"
        if (Regex.Match(date[0], @"^[0][1-9]|[1][0-2]$").Success)
        {
            //if expiration date is after current date
            if ((compareYears == 1) || (compareYears == 0 && (compareMonths == 1)))
            {
                return true;
            }
        }
    }
    return false;
}

我在txt_ExpirationDate中说

时出错
  

它在当前上下文中不存在

我在CryptoEngine.IsValidExpiration上说

也是错误的
  

非静态字段需要对象引用

0 个答案:

没有答案