ValidationHelper.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace Muchinfo.MTPClient.Infrastructure.Helpers
  6. {
  7. /// <summary>
  8. /// 字符串验证公共类 Add By DK 2016-11-22
  9. /// </summary>
  10. public static class ValidationHelper
  11. {
  12. /// <summary>
  13. /// 验证手机号码
  14. /// </summary>
  15. /// <param name="str_handset"></param>
  16. /// <returns></returns>
  17. public static bool IsMobile(string str_handset)
  18. {
  19. return System.Text.RegularExpressions.Regex.IsMatch(str_handset, @"^[1]+[3-9]+\d{9}$");
  20. }
  21. /// <summary>
  22. /// 验证输入为数字
  23. /// </summary>
  24. /// <param name="str_number"></param>
  25. /// <returns></returns>
  26. public static bool IsNumber(string str_number)
  27. {
  28. return System.Text.RegularExpressions.Regex.IsMatch(str_number, @"^[0-9]*$");
  29. }
  30. /// <summary>
  31. /// 验证电话号码
  32. /// </summary>
  33. /// <param name="str_telephone"></param>
  34. /// <returns></returns>
  35. public static bool IsTelephone(string str_telephone)
  36. {
  37. return System.Text.RegularExpressions.Regex.IsMatch(str_telephone, @"^(\d{3,4}-)?\d{6,8}$");
  38. }
  39. /// <summary>
  40. /// 验证身份证号
  41. /// </summary>
  42. /// <param name="str_idcard"></param>
  43. /// <returns></returns>
  44. public static bool IsIDcard(string str_idcard)
  45. {
  46. return System.Text.RegularExpressions.Regex.IsMatch(str_idcard, @"(^(\d{18}$|\d{17}(\d|X|x))$)|(^(\d{15}$|\d{14}(\d|X|x))$)");
  47. }
  48. /// <summary>
  49. /// 验证邮编
  50. /// </summary>
  51. /// <param name="str_postalcode"></param>
  52. /// <returns></returns>
  53. public static bool IsPostalcode(string str_postalcode)
  54. {
  55. return System.Text.RegularExpressions.Regex.IsMatch(str_postalcode, @"^\d{6}$");
  56. }
  57. /// <summary>
  58. /// 验证邮箱
  59. /// </summary>
  60. /// <param name="str_Email"></param>
  61. /// <returns></returns>
  62. public static bool IsEmail(string str_Email)
  63. {
  64. return System.Text.RegularExpressions.Regex.IsMatch(str_Email, @"\\w{1,}@\\w{1,}\\.\\w{1,}");
  65. }
  66. }
  67. }