How to check if pattern validation is valid


i wann check in my after pressing my Save Button if the TextField “username” matches the pattern i have on it. The username.isValid() does not do this.

How have you defined the validator? Can you share your code?

loginName.setLabel("Login Name");
loginName.setTooltipText("Bitte darauf achten alles klein zu schreiben.");

Button speichern = new Button("Speichern", e -> {
			if(mitarbeiterBinder.getBean() != null & !loginPassword.getValue().isEmpty() & !loginName.getValue().isEmpty() & rechteAuswahl.getValue() != null & loginName.isInvalid()){
				mitarbeiterService.addUpdateLogin(mitarbeiterBinder.getBean(), loginName.getValue(), loginPassword.getValue(), rechteAuswahl.getValue());
				new Notification("Gespeichert", 2000, Notification.Position.BOTTOM_CENTER).open();
				new Notification("Loginname, Passwort und Rechtegruppe müssen zum Speichern ausgewählt sein", 2000, Notification.Position.BOTTOM_CENTER).open();

It depends on which version you are. if you are on the latest; Binder’s isValid() and validate() method should also check against the specified pattern. Checking the fields by hand is not really needed if you already have a Binder in place.

1 Like