Validation While Binding

Hello, I am facing problems while validating the form data in Vaadin 14 while binding the field with bean, I want to use some custom validation like :

  1. I want to validate fields using Regax in Java (Using Pattern & Matcher) while binding.
  2. Also the input data should be type safed, if form field allows only number and if user enters the Stirng then proper error message should be shown while binding.

Here’s how I’ve done it…

public class StringUtil {
    public static boolean containsUpperAndLowerCase(String value) {
        final String REGEX = "[A-Z]
.*[a-z]
";
        return Pattern.compile(REGEX).matcher(value).matches();
    }
}

binder.forField(city).asRequired("City is required")
   .withValidator(StringUtil::containsUpperAndLowerCase,"Please use proper noun capitalization")
   .bind(NonAffiliate::getCity, NonAffiliate::setCity);