CH04-L04 · applied

Readable rules for text

Combine several simple checks into one understandable rule.

General CELRuns hereDocumented
What will I learn?

You can build text validation in which every condition can be tested independently.

Where will I try it?

Directly below, in the browser playground.

What do I do?

Run both modes, compare where their values come from, then complete the task.

Try CEL · browser pilot

Try both ways to supply values

Define local values inside one CEL expression, or provide variables as JSON input. Everything runs in your browser.

CEL pilot subset
One self-contained CEL expressioncel.bind() gives a local name to a value and returns the result of the final expression.

cel.bind()cel.bind() is an optional official extension. It is not part of the core CEL language and may not be enabled by every host application.

Tip: press Ctrl/⌘ + Enter to run.
Result

Press Run CEL to evaluate the active example.

Pilot scope: literals, explicit conversions, local cel.bind() variables, JSON variables, lists, maps, presence, collection macros, core string checks, time values, arithmetic, comparisons, logic, and the conditional operator.

What you will do

You will run the prepared expression in the playground above, change one input at a time, and explain the result. Start in CEL only, then repeat the same rule in CEL + JSON.

How it works

A readable validation rule is a sequence of small boolean claims. This one requires non-empty text, at most 20 Unicode code points, and no slash. Short-circuit evaluation also means the expression can stop as soon as one required condition is false.

Read the prepared example

The CEL + JSON rule is:

name != '' && name.size() <= 20 && !name.contains('/')

Its input is:

{
  "name": "CEL guide"
}

The CEL only tab contains the values and the rule in one expression. The enabled cel.bind() extension keeps each name local to its final argument.

Evaluation step by step

  1. The name is not empty.
  2. Its size is within 20 code points.
  3. It contains no slash, so all three conditions return true.

Your task

  1. Run the valid name.
  2. Use an empty string, then a name containing /.
  3. Test a name longer than 20 characters and identify the failing condition each time.

Expected observation: Each invalid value returns false without requiring a special fallback.

Common mistake

Avoid compressing unrelated policy into one opaque regex. Separate checks let readers see the reason for rejection.

Show the explanation

No. A string containing only spaces is not equal to the empty string; trimming would require an enabled extension or host normalization.

Knowledge check

Does this rule trim whitespace before checking emptiness?

Key takeaway

Build validation from simple, named conditions and state any normalization that happens outside CEL.

Sources

  • CEL-DEV — official CEL overview.
  • CEL-LANG — official CEL language definition.
  • CEL-GO-BIND — official documentation for the optional cel.bind() extension used by the self-contained tab.