Skip to content

Commit 04ac91a

Browse files
committed
Correct optional message in ValidatorRegex
1 parent c999827 commit 04ac91a

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

fj-core/src/main/java/org/fugerit/java/core/validator/ValidatorRegex.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ public void configure( Properties atts ) throws ConfigException {
4343
@Override
4444
public boolean validate(ValidatorContext context) throws Exception {
4545
boolean valid = super.validate(context);
46-
if ( !Pattern.matches( this.getRegex() , context.getValue() ) ) {
47-
valid = false;
48-
String message = this.formatMessage( context.getBundle() , ERROR_KEY_REGEX, context.getLabel(), context.getValue(), StringUtils.valueWithDefault( this.getInfo(), this.getRegex() ) );
49-
context.getResult().addError( context.getFieldId(), message );
46+
if ( this.isRequired() && StringUtils.isNotEmpty( context.getValue() ) ) {
47+
if ( !Pattern.matches( this.getRegex() , context.getValue() ) ) {
48+
valid = false;
49+
String message = this.formatMessage( context.getBundle() , ERROR_KEY_REGEX, context.getLabel(), context.getValue(), StringUtils.valueWithDefault( this.getInfo(), this.getRegex() ) );
50+
context.getResult().addError( context.getFieldId(), message );
51+
}
5052
}
5153
return valid;
5254
}

0 commit comments

Comments
 (0)