check 規則
check 驗證單一 stored scalar 的值。它適合數值界線、文字格式與有限集合,例如金額不得為負、代碼符合固定格式,或風險等級只能在產品允許的集合中。
Payload
{
"type": "check",
"name": "訂單編號格式",
"column": "訂單編號",
"op": "matches",
"value": "^ORD-[0-9]{6}$",
"when": [
{ "column": "狀態", "op": "neq", "value": "草稿" }
]
}可用 operator:
- 比較:
lt、lte、gt、gte、eq、neq - Regex:
matches,僅限 string、text、select,pattern 最多 512 字元 - 集合:
in、not_in,非空陣列最多 50 個值
Boolean 與 principal 欄位(principal、user、social_client)只支援 eq、neq、in、not_in。所有 literal 都必須符合欄位型別;decimal 欄位要用純十進位字串("12.50")、以精確值比較,且不能用 matches。
空值不是格式錯誤
欄位是 null 或空字串時,check 不否決。若需求是「有值且格式正確」,請組合 require 與 check;若只在某狀態需要,兩條規則可共用同一組 when。
使用 rules.preview 驗證 regex——preview 不會把 check 套到既有列上——再由 rules.set 發布。違反規則的寫入會回 400 Rule '<name>' violated: '<欄位>' (<值>) must match …(或 must be one of、must not be one of、must be <op> …)。
Last updated on