Client-side validation of text fields
The CSValidator component extension allows client-side validation of TextField, PasswordField, and TextArea components. The field value is validated after each key press without any client-server communication.
The add-on is installed as a JAR, which includes the JavaDoc for the server-side API. You need to compile the widget set.
The version 0.5 and later support Vaadin 7, and come as a component extension, which you can attach to a text field with extend(). For Vaadin 6 compatibility, use version 0.4.x, which offers three components instead of an extension: CSValidatedTextField, CSValidatedPasswordField, and CSValidatedTextArea. The functionality is exactly the same.
The add-on should be considered as beta, as compatibility is not tested with IE, but it probably works.
// Validate full name both on client- and server-side. TextField fn = new TextField("Full Name"); // The regular expression for validation String fn_regexp = "\\w+ \\w+"; // Validate the on client-side final CSValidator validator = new CSValidator(); validator.extend(fn); validator.setRegExp(fn_regexp); validator.setErrorMessage("Full name must be the first name and the last name"); // Validate the on server-side using the same regular expression fn.addValidator(new RegexpValidator(fn_regexp, "Invalid full name")); fn.setRequired(true); fn.setRequiredError("Full name is required");
Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.
- Apache License 2.0
- Vaadin 6.3+
- Vaadin 6.0+ in 0.2.1
- Vaadin 6.2+ in 0.2.2
- Vaadin 6.4+ in 0.3.4
- Vaadin 6.5+ in 0.4.0
- Vaadin 7.0+ in 0.5.0