Class WDoubleValidator
- java.lang.Object
-
- eu.webtoolkit.jwt.WValidator
-
- eu.webtoolkit.jwt.WDoubleValidator
-
public class WDoubleValidator extends WValidator
A validator for validating floating point user input.This validator checks whether user input is a double in the pre-defined range.
i18n
The strings used in this class can be translated by overriding the default values for the following localization keys: Wt.WDoubleValidator.NotANumber: Must be a number Wt.WDoubleValidator.TooSmall: The number must be larger than {1} Wt.WDoubleValidator.BadRange: The number must be in the range {1} to {2} Wt.WDoubleValidator.TooLarge: The number must be smaller than {1}
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WValidator
WValidator.Result
-
-
Constructor Summary
Constructors Constructor Description WDoubleValidator()Creates a new double validator that accepts any double.WDoubleValidator(double bottom, double top)Creates a new double validator that accepts double within the given range.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description doublegetBottom()Returns the bottom of the valid double range.WStringgetInvalidNotANumberText()Returns the message displayed when the input is not a number.WStringgetInvalidTooLargeText()Returns the message displayed when the number is too large.WStringgetInvalidTooSmallText()Returns the message displayed when the number is too small.java.lang.StringgetJavaScriptValidate()Creates a Javascript object that validates the input.doublegetTop()Returns the top of the valid double range.booleanisIgnoreTrailingSpaces()Indicates whether the validator should ignore the trailing spaces.voidsetBottom(double bottom)Sets the bottom of the valid double range.voidsetIgnoreTrailingSpaces(boolean b)If true the validator will ignore trailing spaces.voidsetInvalidNotANumberText(java.lang.CharSequence text)Sets the message to display when the input is not a number.voidsetInvalidTooLargeText(java.lang.CharSequence text)Sets the message to display when the number is too large.voidsetInvalidTooSmallText(java.lang.CharSequence text)Sets the message to display when the number is too small.voidsetRange(double bottom, double top)Sets the range of valid doubles.voidsetTop(double top)Sets the top of the valid double range.WValidator.Resultvalidate(java.lang.String input)Validates the given input.-
Methods inherited from class eu.webtoolkit.jwt.WValidator
getFormat, getInputFilter, getInvalidBlankText, isMandatory, setInvalidBlankText, setMandatory
-
-
-
-
Constructor Detail
-
WDoubleValidator
public WDoubleValidator()
Creates a new double validator that accepts any double.The validator will accept numbers using the current locale's format.
-
WDoubleValidator
public WDoubleValidator(double bottom, double top)Creates a new double validator that accepts double within the given range.The validator will accept numbers using the current locale's format.
-
-
Method Detail
-
getBottom
public double getBottom()
Returns the bottom of the valid double range.
-
setBottom
public void setBottom(double bottom)
Sets the bottom of the valid double range.The default value is the minimum double value.
-
getTop
public double getTop()
Returns the top of the valid double range.
-
setTop
public void setTop(double top)
Sets the top of the valid double range.The default value is the maximum double value.
-
setRange
public void setRange(double bottom, double top)Sets the range of valid doubles.
-
validate
public WValidator.Result validate(java.lang.String input)
Validates the given input.The input is considered valid only when it is blank for a non-mandatory field, or represents a double within the valid range.
- Overrides:
validatein classWValidator
-
setInvalidNotANumberText
public void setInvalidNotANumberText(java.lang.CharSequence text)
Sets the message to display when the input is not a number.The default value is "Must be a number."
-
getInvalidNotANumberText
public WString getInvalidNotANumberText()
Returns the message displayed when the input is not a number.
-
setInvalidTooSmallText
public void setInvalidTooSmallText(java.lang.CharSequence text)
Sets the message to display when the number is too small.Depending on whether
getBottom()andgetTop()are real bounds, the default message is "The number must be between {1} and {2}" or "The number must be larger than {1}".
-
getInvalidTooSmallText
public WString getInvalidTooSmallText()
Returns the message displayed when the number is too small.
-
setInvalidTooLargeText
public void setInvalidTooLargeText(java.lang.CharSequence text)
Sets the message to display when the number is too large.Depending on whether
getBottom()andgetTop()are real bounds, the default message is "The number must be between {1} and {2}" or "The number must be smaller than {2}".
-
getInvalidTooLargeText
public WString getInvalidTooLargeText()
Returns the message displayed when the number is too large.
-
setIgnoreTrailingSpaces
public void setIgnoreTrailingSpaces(boolean b)
If true the validator will ignore trailing spaces.- See Also:
isIgnoreTrailingSpaces()
-
isIgnoreTrailingSpaces
public boolean isIgnoreTrailingSpaces()
Indicates whether the validator should ignore the trailing spaces.- See Also:
setIgnoreTrailingSpaces(boolean b)
-
getJavaScriptValidate
public java.lang.String getJavaScriptValidate()
Description copied from class:WValidatorCreates a Javascript object that validates the input.The JavaScript expression should evaluate to an object which contains a
validate(text)function, which returns an object that contains the following two fields:- fields: a boolean valid,
- a
messagethat indicates the problem if not valid.
Returns an empty string if the validator does not provide a client-side validation implementationq.
- Overrides:
getJavaScriptValidatein classWValidator- See Also:
WValidator.getInputFilter()
-
-