string « Validation « JPA Q&A

1. How do I sanitize string fields containing HTML at model level?

I have an app using Spring, JPA (Hibernate) and the Java validation framework (Hibernate Validator). I would like to be able to annotate fields in our domain model that are allowed ...

2. Is there a way to enforce a minimum string length with NHibernate?

I have a string property on an entity that I would like to mark as required. For example,

public class Product
    public virtual string Name { get; set; }
In ...

3. hibernate validator LengthValidator of truncated string

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, ...

4. Validator for String

Hello I have a constraint for a String attribute, like String city that can only be "New York" or "Orlando"... I believe that this would be made using a check constraint for the city column in the ER world, but how can I make it with Hibernate Validator? I checked the documentation for the basic validators but didn't find. Thank you ...