TextValidationHelper.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace Muchinfo.PC.Common.Helpers
  6. {
  7. public class TextValidationHelper
  8. {
  9. /// <summary>
  10. /// 验证账号是否合法
  11. /// </summary>
  12. /// <param name="account"></param>
  13. /// <returns></returns>
  14. public static bool VaildLoginAccount(string srt)
  15. {
  16. if (!string.IsNullOrEmpty(srt))
  17. {
  18. foreach (var item in srt.ToArray())
  19. {
  20. if (item >= 'A' && item <= 'Z' ||
  21. item >= 'a' && item <= 'z' ||
  22. item >= '0' && item <= '9'
  23. )
  24. continue;
  25. else
  26. {
  27. return false;
  28. }
  29. }
  30. return true;
  31. }
  32. return false;
  33. }
  34. /// <summary>
  35. /// 相差月份
  36. /// </summary>
  37. /// <param name="d1"></param>
  38. /// <param name="d2"></param>
  39. /// <returns></returns>
  40. public static int DifferMonth(DateTime d1, DateTime d2)
  41. {
  42. DateTime max = d1 > d2 ? d1 : d2;
  43. DateTime min = d1 > d2 ? d2 : d1;
  44. int yeardiff = max.Year - min.Year;
  45. int monthdiff = max.Month - min.Month;
  46. return yeardiff * 12 + monthdiff + 1;
  47. }
  48. }
  49. }