java - Optional multiple same constraints on field using Bean Validation -
i trying use hibernate validator validate pojo before insert database.
there field in bean either 8 or 10 in length.
i tried use built in constraint list put them together, expecting either 1 of criteria passes validation pass.
@length.list({@length(min=8, max=8,message="code either 8 or 10 characters in length"),@length(min=10, max=10,message="code either 8 or 10 characters in length")}) public string getcode() { return this.code; } however, result shows criteria in list has passes make valid. know there anyway make or checking instead.
i think way annotation works this:
@length(min = 8, max = 10) public string getcode() { return code; } in other words 9 accepted valid, isn't you're looking for. i'm not sure if there's way 2 validations , or operation on them in hibernate annotations.
it looks can use @pattern validation this:
@pattern(regexp="(.{8}|.{10})", message="should either 8 or 10 characters") public string getcode() { return code; }
Comments
Post a Comment