> **Source:** https://knowledge.leegality.com/document-execution/workflows/v4/rule-engine/how-to/validate-before-proceed > **Site:** Leegality Knowledge Base — https://knowledge.leegality.com > **About:** Leegality is a document execution platform covering eSigning, stamps, NeSL, workflows, and REST API integration. > **Navigation:** Every article on this site has a plain-text version at `.txt` (this format). To get an index of all articles with their `.txt` links, read: https://knowledge.leegality.com/llms.txt > **AI Guide:** For instructions on how to navigate this knowledge base as an AI agent, read: https://knowledge.leegality.com/ai-readable.txt --- # Validate fields before Proceed **Goal:** the workflow must not move past a stage while the data is wrong — and the person running it should be told exactly what to fix. Working example: *every document's IRN must be filled and follow the format `LOAN-123456`; if not, Proceed is blocked and the error names the offending document.* This is a [validation rule](https://knowledge.leegality.com/document-execution/workflows/v4/rule-engine/rule-categories#validation-rules): it runs on a stage's **Proceed**, checks a condition, and raises an error that blocks the stage. Validation is also how "make X mandatory" asks usually ship — this page covers the general pattern, including format checks and checks across *every* item. ## The spec ``` TARGET field: IRN, on every document (including documents added at run time) ACTION: Validate at Proceed (block with error) SUBJECT field: IRN of each document CONDITION: IRN missing, or IRN not matching ^LOAN-[0-9]{6}$ OUTCOME: Proceed on the Create stage is blocked with "IRN is mandatory for document N" or "IRN in document N must follow the format: LOAN-123456"; with all IRNs valid, Proceed goes through Workflow: (yours) ``` Note the spec includes the **error messages word for word** — for validation rules, the message is part of the requirement. ## The rule logic ``` #version 2.0 var curDoc = 1; for(doc in documents) { var irn = doc.irn; if(irn != null) { irn = trim(irn); } if(irn == null || isEmpty(irn)) { throw "IRN is mandatory for document " + curDoc; } else { if(regex(irn, "^LOAN-[0-9]{6}$") == false) { throw "IRN in document " + curDoc + " must follow the format: LOAN-123456"; } } curDoc = curDoc + 1; } ``` Three habits of a good validation rule, all visible here: - **It loops over everything.** `for(doc in documents)` checks every document — including ones the runner adds on the fly — instead of hardcoding "document 1". - **It counts like a human.** `curDoc` starts at 1, so the error says "document 2", never "index 1". - **It layers the checks.** Missing first, then format — the runner gets the most fundamental problem first. One behaviour to know: the rule stops at the **first** offending document per attempt. Fix it, Proceed again, and the next problem (if any) surfaces. That's standard for validations; a single error listing *all* offenders at once is possible in the rule language — ask Support or see Advanced: LEEQL. ## Adapt these parts | Part | In the logic | Change it to | | --- | --- | --- | | What's checked | `doc.irn` | The field to validate (for a pack-level custom field, drop the loop and read `pack.lecf_yourField`) | | The format | `"^LOAN-[0-9]{6}$"` | Your regex — anchored with `^` and `$` so the whole value must match | | Error messages | both `throw` strings | Your exact messages, with the 1-based document number kept in | ## Configure it 1. Rule Engine panel → new rule → **Rule Title**: `IRN mandatory + format on all documents`. 2. Paste the adapted logic into **Create Rule**. 3. **Trigger Method**: **On Proceed Create** — documents and their IRNs live in the Create stage, so that's the Proceed to guard. Validating invitee data instead? Same pattern, **On Proceed Invitee**. 4. Save. Full configuration flow: [Build your first rule](https://knowledge.leegality.com/document-execution/workflows/v4/rule-engine/build-your-first-rule). ## Test it — all three states 1. Leave document 2's IRN empty, Proceed → blocked: *IRN is mandatory for document 2*. 2. Fill it with `LOAN-12` (too short), Proceed → blocked: *IRN in document 2 must follow the format: LOAN-123456*. 3. Fill it with `LOAN-123456`, Proceed → goes through. 4. Add a new document at run time with no IRN, Proceed → blocked again — the loop catches runtime additions too. ## Related The conditional variant — mandatory only when another field says so — is [Make a field mandatory with a rule](https://knowledge.leegality.com/document-execution/workflows/v4/rule-engine/how-to/make-a-field-mandatory). Simple format checks on a single field can also be done without a rule at all, via the field's [Validations](https://knowledge.leegality.com/document-execution/workflows/v4/setup-configuration/field-configuration) tab; use a rule when the check is conditional, spans many items, or needs a custom message.