Created
October 3, 2015 03:51
-
-
Save takeouchida/36195858ad1262ff994f to your computer and use it in GitHub Desktop.
An annotation class for validating IPv4 addresses with Hibernate Validator.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package hibernatevalidator.constraints; | |
import javax.validation.Constraint; | |
import javax.validation.Payload; | |
import javax.validation.ReportAsSingleViolation; | |
import javax.validation.constraints.Pattern; | |
import java.lang.annotation.Documented; | |
import java.lang.annotation.Retention; | |
import java.lang.annotation.Target; | |
import static java.lang.annotation.ElementType.*; | |
import static java.lang.annotation.RetentionPolicy.*; | |
@Pattern(regexp = "^([0-1]?\\d?\\d|2[0-4]\\d|25[0-5])(\\.([0-1]?\\d?\\d|2[0-4]\\d|25[0-5])){3}$") | |
@Target({METHOD, FIELD, ANNOTATION_TYPE}) | |
@Retention(RUNTIME) | |
@Constraint(validatedBy = {}) | |
@Documented | |
@ReportAsSingleViolation | |
public @interface Ipv4 { | |
String message() default "must be ipv4"; | |
Class<?>[] groups() default {}; | |
Class<? extends Payload>[] payload() default {}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment