In free-form text fields, it's sometimes possible to enter a value that isn't valid. For example, when asking for an e-mail address, it might be necessary to validate it against some kind of regular expression such as .+@.+
to provide a simple check.
offset
that allows values between -14
and +12
(by default, IntegerFieldEditor
validates against the 0..MAX_INT
range). Add the following to the createFieldEditors
method:IntegerFieldEditor offset = new IntegerFieldEditor("offset","Current offset from GMT", getFieldEditorParent());offset.setValidRange(-14, +12);addField(offset);
Each field editor can determine what is (or is not) valid, and the validity of the page as a whole is a conjunction of all of the individual field editors' validity. It's also possible to create custom validation rules by creating a subclass of the appropriate FieldEditor
, overriding the isValid
method appropriately.
The error message will show a message like Value must be an Integer between -14 and 12 at the top of the preference page.
3.136.26.20