Chapter 7. Getting Valid Input
In This Chapter
Extracting data from drop-down lists
Managing multiple-selection lists
Getting data from check boxes
Getting information from radio groups
Validating input with regular expressions
Using character, boundary, and repetition operators
Working with pattern memory
It's very nice to be able to get input from the user, but sometimes users make mistakes. It'd be great if some better ways existed to make the user's job easier and prevent certain kinds of mistakes.
Of course, there are tools for exactly that purpose. In this chapter, you get the lowdown on two main strategies for improving user input: specialized input elements and pattern-matching. Together, these tools can help you ensure that the data the user enters is useful and valid.
Getting Input from a Drop-Down List
The most obvious way to ensure that the user enters something valid is to supply valid choices. The drop-down list is an obvious and easy way to do this, as you can see from Figure 7-1.
The drop-down list box approach has a lot of advantages over text-field input:
The user can input with the mouse. This is faster and easier than typing.
No spelling errors. That's because the user doesn't have to type the response.
All answers are available. The user knows which responses are available, because they're in a list.
You can be sure it's a valid answer. That's because you supplied the possible responses.
User responses can be mapped to more complex values. For example, you can show the user ...