Steve Waters
Steve Waters

Reputation: 3548

@Size annotation not trimming whitespace

I have an Entity bean and one of its String-type properties has a @Size annotation as follows:

@PSanityCheck
@Size(min = 8, max = 8, message = "validation.servicecode_length")
@NotEmptyData
@Column(name = "servicecode")
@Field
private String servicecode= "";

However, if I type a string containing a whitespace in the beginning, for example " 1234567" it will accept it as input made of 8 characters. How to make it trim off the whitespace? Is there an annotation for that? The UI is made with Vaadin-framework.

Upvotes: 0

Views: 2259

Answers (1)

running hedgehog
running hedgehog

Reputation: 58

You can use the @Pattern annotation with a regular Expression for this

Upvotes: 2

Related Questions