@Test public void testInvalidIpAddress() { Assert.assertFalse(validator.isValid("192.168.1", context)); Assert.assertFalse(validator.isValid("192.168.1.300", context)); }
@Override public boolean isValid(String value, ConstraintValidatorContext context) { if (!InetAddressValidator.getInstance().isValidInet4Address(value)) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(String.format("%s is invalid IPv4 Address", value)) .addConstraintViolation(); return false; } return true; }
IPv4Validator implements ConstraintValidator<IPv4, String> { @Override public boolean isValid(String value, ConstraintValidatorContext context) { if (!InetAddressValidator.getInstance().isValidInet4Address(value)) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(String.format("%s is invalid IPv4 Address", value)) .addConstraintViolation(); return false; } return true; } }
IPv4Validator implements ConstraintValidator<IPv4, String> { @Override public boolean isValid(String value, ConstraintValidatorContext context) { if (!InetAddressValidator.getInstance().isValidInet4Address(value)) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(String.format("%s is invalid IPv4 Address", value)) .addConstraintViolation(); return false; } return true; } @Inject  IPv4Validator(); }
IPv4Validator implements ConstraintValidator<IPv4, String> { @Override public boolean isValid(String value, ConstraintValidatorContext context) { if (!InetAddressValidator.getInstance().isValidInet4Address(value)) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(String.format("%s is invalid IPv4 Address", value)) .addConstraintViolation(); return false; } return true; } @Inject  IPv4Validator(); @Override void initialize(IPv4 constraintAnnotation); @Override boolean isValid(String value, ConstraintValidatorContext context); }
IPv4Validator implements ConstraintValidator<IPv4, String> { @Override public boolean isValid(String value, ConstraintValidatorContext context) { if (!InetAddressValidator.getInstance().isValidInet4Address(value)) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(String.format("%s is invalid IPv4 Address", value)) .addConstraintViolation(); return false; } return true; } @Inject  IPv4Validator(); @Override void initialize(IPv4 constraintAnnotation); @Override boolean isValid(String value, ConstraintValidatorContext context);  }