CheckData.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. namespace Bowin.Common.Utility
  7. {
  8. public class CheckData
  9. {
  10. /// <summary>
  11. /// 判断日期的格式
  12. /// </summary>
  13. /// <param name="dateText">输入日期的字符串</param>
  14. /// <returns></returns>
  15. public static bool isDataFormal(string dateText)
  16. {
  17. bool result = false;
  18. if (dateText.Length > 0)
  19. {
  20. DateTime dtstate = DateTime.MinValue;
  21. DateTime.TryParse(dateText, out dtstate);
  22. if (dtstate != DateTime.MinValue)
  23. {
  24. result = true;
  25. }
  26. }
  27. else
  28. {
  29. result = true;
  30. }
  31. return result;
  32. }
  33. /// <summary>
  34. /// 判断正整数的格式
  35. /// </summary>
  36. /// <param name="Str"></param>
  37. /// <returns></returns>
  38. public static bool isPositiveInt(string Str)
  39. {
  40. bool _isPositiveInt = false;
  41. string matchStr = "";
  42. matchStr += @"^[1-9]\d*$";
  43. RegexOptions option = (RegexOptions.IgnoreCase | (RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace));
  44. if (Regex.IsMatch(Str, matchStr, option))
  45. _isPositiveInt = true;
  46. else
  47. _isPositiveInt = false;
  48. return _isPositiveInt;
  49. }
  50. }
  51. }