[ fromfile: ex-validation.xml id: ex-validation ]
Design an Address Form like that shown in Figure 14.6.
When the user selects a country from the combo box, the program must set an appropriate validator on the stateEdit
, zipEdit
, and phoneEdit
QLineEdit widgets.
Also, the dialog labels should change in the following ways:
USA:
Set the zipLabel
to Zip.
Set the stateLabel
to State.
Canada:
Set the zipLabel
to Postal Code.
Set the stateLabel
to Province.
Add another country of your choice with appropriate validators.
Make sure that invalid inputs are never accepted (disable the src/handouts/validation/addressform.ui
if you like.
International Standard Book Number (ISBN) is a coding system for books and other publications. ISBNs come in different sizes (10-digit and 13-digit) and they break down into substrings that identify language group, publisher, and title. In addition, the rightmost digit is a check digit that is computed from the other digits for error detection. [63]
Assume that the ISBN-10 code (including the check digit) looks like this:
d1d2d3...d9d10
Then the following equation must balance:
(10*d1 + 9*d2 + 8*d3 + ... + 2*d9 + d10) % 11 = 0
If the required value for the check digit is 10, use the letter 'X' in that position.
Define a QValidator that accepts an ISBN-10 code if and only if it has a correct check digit. You can test it with 0-306-40615-2 (valid) and 0-306-40615-5 (invalid).
Find out (e.g., from the Wikipedia article) how to validate the check digit for an ISBN-13 code and define a QValidator that accepts one if and only if its check digit is correct.
Can you make a single QValidator that can handle both ISBN-10 and ISBN-13 codes (validating only the check digit)?
Generated: 2012-03-02 | © 2012 Alan Ezust and Paul Ezust. |