سؤال

Is there a similar annotation to @Length in hibernate validator but it restricted on a trimmed string.

For example:

I have

@Length(max= 2);
String str;

when: str = " ab";
--> it will pass ok.

Thanks,

هل كانت مفيدة؟

المحلول

As fare i know, there isn't one.

But you can easely implement your own.

The other (not so good) way is to add a getter which trim the string.

@Length(max= 2);
String getTrimmedStr() {
   return this.str.trim();
}

But i think implementing your own Validator is the much cleaner approach.

نصائح أخرى

I don't think so, but you can easily implement one with javax.validation, by extending the LengthValidator

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top