| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using System.Windows.Controls;
- namespace TeamAAS_VP.Identity
- {
- public class IPValidationRule:ValidationRule
- {
- public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
- {
-
- if (IsValidIP(value.ToString()))
- {
- return new ValidationResult(true, null);
- }
- else
- {
- return new ValidationResult(false, "Invalid_Address");
- }
- }
- private bool IsValidIP(string ip)
- {
- if (string.IsNullOrWhiteSpace(ip))
- return false;
- string[] parts = ip.Split('.');
- if (parts.Length != 4)
- return false;
- foreach (var part in parts)
- {
- if (!byte.TryParse(part, out byte b))
- return false;
- }
- return true;
- }
- }
- }
|