Created
October 3, 2015 04:05
-
-
Save takeouchida/b520471123bca4f71c4d to your computer and use it in GitHub Desktop.
An annotation class for validating mac 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-9a-fA-F]{2})(:[0-9a-fA-F]{2}){5}$") | |
@Target({METHOD, FIELD, ANNOTATION_TYPE}) | |
@Retention(RUNTIME) | |
@Constraint(validatedBy = {}) | |
@Documented | |
@ReportAsSingleViolation | |
public @interface Macaddr { | |
String message() default "must be macaddr"; | |
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
Great work, thanks for this.
It would be great if couple of lines are added about the usage. That will be even more helpful.