Sub topic 4
Choose between rejecting input and showing a warning
This chapter assumes you can select ranges, enter values and formulas, and have already created a drop-down from a typed list. You should also be comfortable with references like A2 and $A$2. Every validation rule in Google Sheets has to answer one question: what happens when someone enters a value that breaks the rule? This chapter covers the two answers, how to set each one, and how to choose.
The two behaviors
A rule can respond to invalid input in one of two ways:
- Reject the input. Sheets shows a message and discards the entry. The cell keeps whatever it held before.
- Show a warning. Sheets accepts the entry and flags the cell with a small red triangle in its top-right corner. Hovering over the triangle shows a message saying the value is invalid.
The setting belongs to each rule, not to the sheet. Two rules on two ranges in the same sheet can behave differently. The rule's criteria decide whether a value is valid. This setting decides only what happens to a value that fails.
Set the behavior in the interface
- Select the cells the rule applies to, for example
C2:C100. - Open Data, then Data validation, and select Add rule. If a rule already exists on the range, select it to edit it.
- Choose the criteria, such as Dropdown or Number.
- Expand Advanced options.
- Under If the data is invalid, choose Show a warning or Reject the input.
- Select Done.
The default differs between tools. The Sheets interface and Apps Script start from different defaults, as the Apps Script section below shows. Check the setting on every rule you create instead of relying on what you remember.
How each mode behaves in practice
Take a status column with a drop-down containing Not started, In progress and Done. A user types Finished into one of the cells.
| Aspect | Reject the input | Show a warning |
|---|---|---|
| Value stored in the cell | No. The previous value stays. | Yes. `Finished` is stored. |
| Feedback to the user | A message appears at the moment of entry. | A red triangle stays on the cell. The message shows on hover. |
| Can invalid data enter through typing? | No. | Yes. |
| Feedback is hard to miss | Yes. | No. The triangle is small. |
| Typical use | Values that other formulas depend on. | Soft limits and values that need review. |
With a drop-down in warning mode, a value not in the list is stored as plain text instead of a chip. It sits in the cell like any other text. A formula such as =COUNTIF(C2:C100, "Done") simply does not count it.
Reject mode does not make the data fully safe. It blocks typing, but other routes can still put invalid values into cells. Pasting is the main one, and the chapter on the limits of validation covers it. Do not treat rejection as a guarantee.
Choose by what depends on the value
Pick the mode by asking what breaks downstream if a bad value gets in.
Reject when the value is a key that something else reads exactly. Examples:
- Status values counted by
COUNTIF. - Category names that a lookup matches.
- IDs that must be unique.
- Dates that a formula subtracts, where text would produce errors.
In these cases a wrong entry silently corrupts results. A message at entry time costs the user a few seconds and prevents hours of tracing a wrong total.
Warn when the rule describes what is normal, not what is possible. Examples:
- An hours estimate that is usually under 40 but can legitimately reach 60.
- A discount that normally stays under 20% but is occasionally approved higher.
- A free-text field where you want to nudge people toward existing spellings.
- A sheet where several people enter data and an occasional exception is expected, but you want to see exceptions at a glance.
Rejecting in these cases trains users to enter a fake value that passes the rule, such as 40 when the real estimate is 60. A false value that looks valid is worse than a flagged true one.
A third case is a sheet you are tightening over time. Start with warnings, review the cells with red triangles to see what real data looks like, fix the rule or the data, and switch to reject once the warnings are rare.
Worked example: a task tracker
You build a tracker with these columns:
| Column | Content | Rule | Setting |
|---|---|---|---|
| A | Task ID | Custom formula for uniqueness | Reject |
| B | Due date | Date on or after 1 January 2025 | Reject |
| C | Status | Drop-down of three items | Reject |
| D | Estimate in hours | Number between 0 and 40 | Warning |
The reasoning for each column:
- Task ID (A). Two tasks with one ID break any lookup by ID, so duplicates must not get in. Use the custom formula from the spine, applied to
A2:A100:
=COUNTIF($A$2:$A$100, A2)=1The formula is true only when the value in A2 appears exactly once in the range. Entering a second copy makes the count 2, so the rule fails. Choose Reject the input.
- Due date (B). A date compared against
TODAY()or used in subtraction must be a real date, not text. Use the built-in date criteria and reject. The custom formula=AND(ISNUMBER(B2), B2>=DATE(2025,1,1), B2<=TODAY())also works when you need an upper bound of today. Pick the one that matches your actual rule. If a task due next month is legitimate,B2<=TODAY()is the wrong upper bound. - Status (C). The status counts feed a summary, so reject anything outside the list.
- Estimate (D). A 60-hour task is unusual but real. Use Number, between,
0and40, and choose Show a warning. The red triangle tells a reviewer to double-check the estimate without blocking the person who entered it.
Test each rule after you build it:
- Type a valid value. It should be accepted with no triangle.
- Type an invalid value. In a reject column the entry should disappear and a message should appear. In a warning column the value should stay and a triangle should appear.
- Clear the cell by pressing Delete. Clearing is allowed in both modes, and the empty cell keeps its rule.
Set the behavior with Apps Script
In Apps Script, the invalid-data setting is setAllowInvalid. Its name reads backward from the interface:
setAllowInvalid(false)means invalid input is rejected.setAllowInvalid(true)means invalid input is allowed with a warning.
The default when you build a rule in Apps Script is true, which is a warning. If you forget to call the method, your rule warns instead of rejecting. The spine's addStatusDropdown function sets false explicitly for that reason.
This function applies the estimate rule from the tracker, in warning mode:
function addEstimateWarning() {
const sheet = SpreadsheetApp.getActiveSheet();
const rule = SpreadsheetApp.newDataValidation()
.requireNumberBetween(0, 40)
.setAllowInvalid(true)
.setHelpText('Estimates above 40 hours are allowed but will be flagged.')
.build();
sheet.getRange('D2:D100').setDataValidation(rule);
}To check which mode an existing rule uses, read it back from a cell:
function describeInvalidHandling() {
const cell = SpreadsheetApp.getActiveSheet().getRange('C2');
const rule = cell.getDataValidation();
if (rule === null) {
Logger.log('No validation rule on ' + cell.getA1Notation());
return;
}
Logger.log(rule.getAllowInvalid() ? 'Warning' : 'Reject');
}getDataValidation() returns null when the cell has no rule, so the check for null is required. Without it the next line throws an error on an unvalidated cell. The function reads one cell. If a range has mixed rules, check a cell from each section.
Common mistakes
- Reading the Apps Script flag backward.
setAllowInvalid(true)sounds strict and is the lenient setting. Add a comment next to each call. - Using a warning where formulas depend on exact values. The bad value is stored, and the red triangle is easy to miss in a long column. Counts and lookups then quietly produce wrong results.
- Using reject for a soft limit. People enter a fake value to get past the rule. The data looks clean and is wrong.
- Trusting reject mode to guarantee clean data. It governs typed entry. Pasted values and values that existed before the rule are outside its reach.
- Assuming a formula's result is checked. Validation looks at values people enter. A formula in a validated cell can return a value that would fail the rule, and Sheets does not stop it.
- Mixing modes in one column without a reason. If part of a column rejects and part warns, users cannot predict what will happen. Apply one rule per column unless the sections really differ.
What to remember
The criteria define what is valid. The invalid-data setting defines the consequence. Use reject for values that other formulas read exactly. Use a warning for limits that have legitimate exceptions. Always check the setting you ended up with, in the interface or with getAllowInvalid(), because the defaults differ between the two. The next chapter covers help text and drop-down appearance, which makes either mode easier to understand for the person entering data.
Exercise
A budget sheet has column E for "Discount %". Discounts are normally 0 to 20, but managers sometimes approve up to 35. You want those larger discounts visible for review, and you want to prevent text such as "ten" from ever being stored. Which criteria and invalid-data setting would you use, and what limitation remains?
Show answer
Use a Number rule between 0 and 20 with "Show a warning", so values from 21 to 35 are stored and flagged with a red triangle for review. This does not prevent text such as "ten", because a warning stores any invalid value. To block text while still allowing 0 to 35, use a Number rule between 0 and 35 with "Reject the input", and flag values above 20 separately, for example with conditional formatting. In either design, pasted values are not guaranteed to be checked.
Exercise
What does this Apps Script rule do when someone types "Blocked" into a cell it covers, and what single change would make it reject the entry? const rule = SpreadsheetApp.newDataValidation() .requireValueInList(['Not started', 'In progress', 'Done'], true) .setAllowInvalid(true) .build();
Show answer
Because setAllowInvalid(true) means invalid input is allowed with a warning, "Blocked" is stored in the cell and the cell shows a red triangle. Changing it to setAllowInvalid(false) makes the rule reject the entry, so the cell keeps its previous value.