In free-form text fields it's sometimes possible to input a value that doesn't make sense. For example, when asking someone for their e-mail address it might be necessary to validate it against some kind of regular expression like .+@.+
to provide a simplistic test. Perform the following steps:
To test the default validation, run the Eclipse instance and go to the Clock preference page. Type some text in the numeric field. A warning message will be displayed as shown in the following screenshot:
To add validation, create a new field called
offset
which allows valid values between-14
and+12
. (By default,IntegerFieldEditor
validates against the range0
toMAX_INT
.) Add the following to thecreateFieldEditors()
method:IntegerFieldEditor offset = new IntegerFieldEditor("offset","Current offset from GMT", getFieldEditorParent()); offset.setValidRange(-14, +12); addField(offset);
Run the Eclipse instance, go to the Clock preference page and...