File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed
engine/src/main/java/org/hibernate/validator/internal/constraintvalidators/bv Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change 9
9
import jakarta .validation .constraints .NotBlank ;
10
10
11
11
/**
12
- * Check that a character sequence is not {@code null} nor empty after removing any leading or trailing whitespace .
12
+ * Check that a character sequence is not {@code null} nor {@link String#isBlank() blank} .
13
13
*
14
14
* @author Guillaume Smet
15
15
*/
16
16
public class NotBlankValidator implements ConstraintValidator <NotBlank , CharSequence > {
17
17
18
18
/**
19
- * Checks that the character sequence is not {@code null} nor empty after removing any leading or trailing
20
- * whitespace.
19
+ * Checks that the character sequence is not {@code null} nor {@link String#isBlank() blank}.
21
20
*
22
21
* @param charSequence the character sequence to validate
23
22
* @param constraintValidatorContext context in which the constraint is evaluated
24
- * @return returns {@code true} if the string is not {@code null} and the length of the trimmed
25
- * {@code charSequence} is strictly superior to 0, {@code false} otherwise
23
+ * @return returns {@code true} if the string is not {@code null} and
24
+ * the call to {@link String#isBlank() charSequence.isBlank()} returns {@code false}, {@code false} otherwise
25
+ * @see String#isBlank()
26
26
*/
27
27
@ Override
28
28
public boolean isValid (CharSequence charSequence , ConstraintValidatorContext constraintValidatorContext ) {
29
29
if ( charSequence == null ) {
30
30
return false ;
31
31
}
32
32
33
- return charSequence .toString ().trim (). length () > 0 ;
33
+ return ! charSequence .toString ().isBlank () ;
34
34
}
35
35
}
You can’t perform that action at this time.
0 commit comments