RegularHelper.cs 494 B

123456789101112131415161718
  1. using System.Text.RegularExpressions;
  2. namespace Team.Utility
  3. {
  4. public static class RegularHelper
  5. {
  6. public static bool CheckIpAddress(string ip)
  7. {
  8. if (string.IsNullOrWhiteSpace(ip))
  9. {
  10. return false;
  11. }
  12. Regex ipRegex = new
  13. (@"^((2[0-4]\d|25[0-5]|(1\d{2})|([1-9]?[0-9]))\.){3}(2[0-4]\d|25[0-4]|(1\d{2})|([1-9][0-9])|([1-9]))$");
  14. return ipRegex.IsMatch(ip);
  15. }
  16. }
  17. }