protected String safeStringFromProperty ( StringProperty stringProperty , String field , List < FieldError > errorsBuilder , int maxLen , StringFieldType fieldType ) { String s = stringProperty . get ( ) ; if ( fieldType == StringFieldType . OPTIONAL && s . length ( ) > maxLen ) { errorsBuilder . add ( new FieldError ( "field must be less than " + maxLen + " characters" , field ) ) ; } else if ( fieldType != StringFieldType . OPTIONAL && ( s . length ( ) > maxLen || s . isEmpty ( ) ) ) { errorsBuilder . add ( new FieldError ( "field must not be blank and less than " + maxLen + " characters" , field ) ) ; } if ( fieldType == StringFieldType . VARIABLE && ! s . matches ( "^[\\p{L}_$][\\p{L}\\p{N}_]*$" ) ) { errorsBuilder . add ( new FieldError ( "Function fields must use only letters, digits, and '_'" , field ) ) ; } else if ( ! s . matches ( "^[\\p{L}\\p{N}\\s\\-_*%()]*$" ) ) { errorsBuilder . add ( new FieldError ( "Text can only contain letters, numbers, spaces and '-_()*%'" , field ) ) ; } return s ; }
Gets the string value from a text field and validates it is correct in terms of length and content .