private static void Validate(IpAddress entity) { if (StringUtils.IsBlank(entity.IpAddressValue)) { throw new InvalidIpAddressException("IP Address cannot be blank"); } const string pattern = @"[0-9]{1,3}(.[0-9]{1,3}){3,3}"; if (!Regex.IsMatch(entity.IpAddressValue, pattern)) { throw new InvalidIpAddressException("The entered value does not appear to be a valid IP address"); } IpAddressFinder finder = new IpAddressFinder(); finder.IpAddressValue = entity.IpAddressValue; IpAddress ipAddress = IpAddress.FindOne(finder); if (!ipAddress.IsNull) { if (entity.IsNew) { throw new InvalidIpAddressException("That IP Address already exists"); } if (entity.IpAddressId.Equals(ipAddress.IpAddressId)) { throw new InvalidIpAddressException("That IP Address already exists"); } } }