This article is a mirror article of machine translation, please click here to jump to the original article.

View: 22266|Reply: 0

[Source] C# is a method of determining whether a 6-digit number entered by a user is a date

[Copy link]
Posted on 6/12/2015 10:25:13 AM | | |
  1. /// <summary>   
  2.         /// 判断输入是否为日期类型   
  3.         /// </summary>   
  4.         /// <param name="s">待检查数据</param>   
  5.         /// <returns></returns>   
  6.         public static bool IsDate(string s)
  7.         {
  8.             try
  9.             {
  10.                 //例如:201506
  11.                 s = s.Insert(4, "/");
  12.                 DateTime d = DateTime.Parse(s);
  13.                 return true;
  14.             }
  15.             catch
  16.             {
  17.                 return false;
  18.             }
  19.         }
Copy code
I found some methods from the Internet, and then I changed it myself.

The correct date returned by the user, for example, 201503

A user entering an incorrect date returns false, for example, 201555




Previous:Use regular expressions to make C# determine whether the input date format is correct
Next:C# language method of "converting string format datetime strings to DateTime type"
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com