Validator.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Text.RegularExpressions;
  5. namespace CP.Common
  6. {
  7. public class Validator
  8. {
  9. /// <summary>
  10. /// 手机号码判断
  11. /// </summary>
  12. /// <param name="str"></param>
  13. /// <returns></returns>
  14. public static bool IsPhone(string str)
  15. {
  16. string s = @"^(13[0-9]|15[0-9]|18[0-9]|14[0-9]|17[0-9]|16[0-9])\d{8}$";
  17. if (Regex.IsMatch(str, s))
  18. return true;
  19. return false;
  20. }
  21. /// <summary>
  22. /// 验证邮箱
  23. /// </summary>
  24. /// <param name="strEmail"></param>
  25. /// <returns></returns>
  26. public static bool IsValidEmail(string strEmail)
  27. {
  28. return Regex.IsMatch(strEmail, @"^[\w\.]+([-]\w+)*@[A-Za-z0-9-_]+[\.][A-Za-z0-9-_]");
  29. }
  30. /// <summary>
  31. /// 是否是数字
  32. /// </summary>
  33. /// <param name="str"></param>
  34. /// <returns></returns>
  35. public static bool IsValidNumber(string str)
  36. {
  37. return Regex.IsMatch(str, @"^(\d+)");
  38. }
  39. }
  40. }