javax.validation to validate list of values?

前端 未结 3 736
南笙
南笙 2020-12-28 13:06

is there a way to use javax.validation to validate a variable of type string called colour that needs to have these values only(red, blue, green, pink) using annotations?

3条回答
  •  执念已碎
    2020-12-28 13:41

    In that case I think it would be simpler to use the @Pattern annotation, like the snippet below. If you want a case insensitive evaluation, just add the appropriate flag:

    @Pattern(regexp = "red|blue|green|pink", flags = Pattern.Flag.CASE_INSENSITIVE)

提交回复
热议问题