Lesson 69: Presence and format checks
Trang này cần trình duyệt gần đây (hỗ trợ SharedArrayBuffer). Vui lòng cập nhật Chrome, Edge, Firefox hoặc Safari lên phiên bản mới nhất.
English
Two more validation checks
- Lesson 40 had the range, length and type checks. Here are two more.
- A presence check: something was entered (the field is not empty).
- A format check: the data has the right pattern, for example 2 letters then 4 digits.
| Check | Example | What it rejects |
|---|---|---|
| presence | a name must be entered | an empty line |
| format | ID like AB1234 | A12345, ab1234, AB12C4 |
| length | ID has 6 characters | AB123 |
| check digit | the last digit is worked out from the others (lesson 41) | a mistyped code |
English
In the exam
- 0478/22/F/M/25 Q4(a): state the purpose of a presence check. Mark scheme: to check that a value has been entered.
- 0478/23/M/J/23 Q5(a): link each description to a check. Data is an integer: type check; some data has been entered: presence check; the right number of characters: length check; an identification number contains no errors: check digit. (The format check is not used there.)
Độ khó 2/5 · 140 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
A presence check makes sure that something was entered. Type a name in the Serial Monitor; if the line is empty, print Error: enter a name instead of booking. Check sends an empty line first, then Ana.
Nhấn Chạy để xem kết quả ở đây.
Độ khó 4/5 · 280 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
A format check makes sure the data has the right pattern. A student ID is 2 capital letters and then 4 digits, like AB1234. Finish validId: return false if the length is not 6, if one of the first 2 characters is not a capital letter, or if one of the last 4 is not a digit.
Nhấn Chạy để xem kết quả ở đây.