Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
A hotel stores its bookings in a table. For each field, choose one suitable validation check and say what it checks.
BookingRef: always the letter H then four digitsGuestName: must be filled inNights: a whole number from 1 to 7Email: must be filled in and must contain the @ symbolValidation is an automatic check that data is sensible before it is stored: a range check, a length check, a type check, a presence check, a format check or a check digit. A field can need several checks. Validation cannot prove that a sensible value is the true one.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Step 1. BookingRef. A format check: H and then four digits. A length check (exactly characters) also helps.
Step 2. GuestName. A presence check: the field is not empty.
Step 3. Nights. A type check (a whole number) and a range check from to .
Step 4. Email. A presence check, and a format check that the text contains the @ symbol.
Answer: format (and length) for BookingRef, presence for GuestName, type and range for Nights, presence and format for Email.
Log in to join the discussion.
Loading…