I need to have a text-field which shows validation messages on entering special characters such. How can i do that? I used the following method to implement this but its the message is not clearing on entering right text. Is there any other way i can do this?
if (! ((String) textfield.getValue()).matches(“^\w*$”)) {
// Put the component in error state and
// set the error message.
textfield.setComponentError(
new UserError(“Must be letters and numbers”));
}
Add a ValueChangeListener to the field and check the value. Als call setImmediate(true) on the field
There is also a client side validation addon which could be the fastest
Add a RegexpValidation to the field the set the Form to writeThrough = true (if your using a form) (not directly validates, but after leaving the field)