CSValidation
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.
You have two options for validating the values: regular expressions and JavaScript. The JavaScript return value can also be used to create counters in text fields and areas. The library comes with special JavaScriptEditor and RegExpEditor components, which allow you to develop and test JavaScript and regular expression validators easily. The editors are also available in the demo.
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.
Sample code
final TextField postcode = new TextField("Postal Code"); final CSValidator validator = new CSValidator(); validator.extend(postcode); validator.setJavaScript("if (value >= 0 && value < 10000)" + " \"partial\";" + "else if (value >= 10000 && value <= 99999)" + " null;" + "else" + " \"Postal Code must be a 5-digit number between 10000 and 99999\";"); layout.addComponent(postcode);
// 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");
Links
Compatibility
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.
Version
Fixed a problem with PreventInvalidTyping.
- Released
- 2015-05-08
- Maturity
- BETA
- License
- Apache License 2.0
Compatibility
- Framework
- Vaadin 7.0+
- Vaadin 6.0+ in 0.2.1
- Vaadin 6.2+ in 0.2.2
- Vaadin 6.3+ in 0.3.0
- Vaadin 6.4+ in 0.3.4
- Vaadin 6.5+ in 0.4.0
- Browser
- Firefox
- Safari
- Google Chrome
CSValidation - Vaadin Add-on Directory
Client-side validation of text fieldsAPI Documentation
Project Home Page
Online Demo
Discussion Forum
CSValidation version 0.2.1
null
CSValidation version 0.2.2
null
CSValidation version 0.3.0
New CSValidatedTextArea component for multi-line text area. Setting setRows() does not make the regular CSValidatedTextField multi-line, but you have to use this class.
New "valid" and "partial" keywords for JavaScript evaluation results that allow specifying a message after the keyword. The valid and partial messages are displayed in the same area as the error messages. This makes creation of various counters, for example, very easy.
Validation is now done also for empty fields. This may change the behavior of existing applications.
CSValidation version 0.3.1
* Added setValidateEmpty() method that, when set true, forces validation of new fields even when they are empty.
* Enhanced the demo framework greatly
CSValidation version 0.3.3
Fixes JavaScript evaluation problem in at least Safari and Chrome and possibly some other browsers. Opera still doesn't work with multi-line text areas with newlines.
CSValidation version 0.3.4
Compatibility for Java 5 (jre_1.5).
CSValidation version 0.4.0
Changed package name from com.vaadin.csvalidation to org.vaadin.csvalidation.
Validate also empty values with regular expressions (support for example [0-9]*), unless disabled with setValidateEmptyValue(false).
Fixed a problem with span elements, for example in CssLayout. Compiled with Vaadin 6.5.4 and GWT 2.1.1, but could work with earlier versions as well.
CSValidation version 0.4.1
Fixed invalid JAR. Most files were lost because of the com->org change in packaging.
Changes in 0.4:
* Changed package name from com.vaadin.csvalidation to org.vaadin.csvalidation.
* Validate also empty values with regular expressions (support for example [0-9]*), unless disabled with setValidateEmptyValue(false).
* Fixed a problem with span elements, for example in CssLayout.
* Compiled with Vaadin 6.5.4 and GWT 2.1.1, but could work with earlier versions as well.
CSValidation version 0.5.0
Supports Vaadin 7. Validation is done using a CSValidator component extension, not components as in the Vaadin 6 version. Not Vaadin 6 compatible.
CSValidation version 0.5.1
Fixed for the stable Vaadin 7.0.0 API.
CSValidation version 0.5.2
Fixed a problem with PreventInvalidTyping.
CSValidation version 0.5.3
Fixes the problem that the JAR was built with JDK 1.8, now it's with JDK 1.6.
CSValidation version 0.5.4
Fixed the invalid widget set name in the add-on JAR manifest, which caused a faulty inherits statement in automatically generated .gwt.xml descriptors.
CSValidation version 0.5.5
Corrected missing class files.
CSValidation version 0.5.6
Fixed a Maven dependency problem.