• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 5. SWT Text Fields > Performing Field Validation

5.13. Performing Field Validation

The focus event can also be used to perform field-level validation. You must perform two tasks when you undertake this type of validation. First, you must compare the text in the field at the time the event occurs with an expected value, such as the length of the entered text compared to a fixed length. Second, you must prevent the focus from leaving the text field in the event that the text entered is not valid.

5.13.1. How do I do that?

To perform field-level validation and prevent the user from switching away from a text field until the contents pass the validation test, you must again use a FocusListener. Example 5-5 demonstrates how to perform validation on text2 by comparing the contents entered by the user with a known value.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint