0

Is there an annotation in javax validation, so it should constraint that value is one of predefined values. Example

@OneOf(values = "12-14m, 16m, 18m")
private String size;
Romper
  • 2,009
  • 3
  • 24
  • 43
  • 1
    As it is a string field you can try to use `@Pattern` and combine the allowed things through or. Something like `@Pattern( regexp = "(12|13|14|16|18)m")`. But as suggested there's nothing like that by default. So either write your own, or try the pattern. – mark_o Sep 07 '17 at 14:05

2 Answers2

0

If you are using hibernate-validator, you can declare new annotation using @ConstraintComposition. This is a good example here.

linarkou
  • 1
  • 2