package com.vaadin.data.validator; /** * Validator base class for validating strings. See * {@link com.vaadin.data.validator.AbstractValidator} for more * information. * *

* If the validation fails, the exception thrown contains the error message with * its argument 0 replaced with the string being validated. *

* * @author IT Mill Ltd. * @version * @VERSION@ * @since 5.4 */ @SuppressWarnings("serial") public abstract class AbstractStringValidator extends AbstractValidator { /** * Constructs a validator for strings. *

* Null and empty string values are always accepted. To disallow empty * values, set the field being validated as required. *

* * @param errorMessage * the message included in the exception (with its parameter {0} * replaced by the string to be validated) in case the validation * fails */ public AbstractStringValidator(String errorMessage) { super(errorMessage); } public boolean isValid(Object value) { if (value == null) { return true; } if (!(value instanceof String)) { return false; } return isValidString((String) value); } /** * Checks if the given string is valid. * * @param value * String to check. Can never be null. * @return true if the string is valid, false otherwise */ protected abstract boolean isValidString(String value); }