I am using Java's Validator class to validate some input fields from my Spring Object class. I am validating URIs, and they can be in either format, http:/myURL/uri, or "readFromURI.v1". Originally, I was just validating the first part, so my Object class had:
@Pattern(regexp="[\\w\\s.,;:*&@(){}+-=?/|!\\[\\]%#$~]{0,512}", message="incorrect format")
private String URI;
Now, if the user selects a checkbox in my app, they will enter in the value as the second format, so I created a new regexp:
@Pattern.List({
@Pattern(regexp="[\\w\\s.,;:*&@(){}+-=?/|!\\[\\]%#$~]{0,512}", message="incorrect format"),
@Pattern(regexp="^\"(Create|Read|Update|Delete)[a-zA-Z]+.*vd+\"${0,512}", message="incorrect format")
})
private String URI;
The regexp is probably wrong for the second part, and I will probably ask that question at a later time. But now whenever I validate either format it fails both conditions. So I'm assuming that the way I wrote it, it's trying to apply both regex's. How can I choose one based on a value? That value field is in the same Class if that helps:
private String URI;
private boolean useHttp; //if true, validate using [\\w\\s.,;:*&@(){}+-=?/|!\\[\\]%#$~]{0,512}