Reject scans that don’t match what a ScanField expects, before they reach your data.
ZipZapKit hasn’t been released yet. The API names on this page are provisional and may change.
Validation checks each scan against rules you set and rejects the ones that fail. A rejected scan never reaches your binding, so your app only ever sees values it can use.Use it when a wrong scan is likely or costly: labels with several barcodes on them, numbers that people sometimes type by hand, or fields where a bad value causes trouble later.
This field accepts retail product barcodes and rejects any value whose check digit is wrong.
How it works
Every scan goes through the same steps, in this order:
Barcode type. Is this one of the types the field accepts? See Barcode types.
Normalization. The value is converted to the form you asked for. See Normalization.
Validation. Each rule checks the normalized value.
Your binding. If every rule passes, the value is written.
Because validation runs after normalization, write your rules for the form you store. If you normalize to 14-digit GTINs, validate 14 digits.Barcode types and validation answer different questions. Barcode types decide which barcodes are read at all. Validation decides whether what was read is acceptable.
Rules
Add one .validate modifier for each rule. A scan has to pass all of them.
Check digit
.validate(.checkDigit)
Recalculates the check digit and rejects the value if it doesn’t match. It applies to GTINs (UPC-A, UPC-E, EAN-13, EAN-8, ITF-14) and passes other values through.A scanner already verifies the check digit of a UPC or EAN while reading it, so this rule matters most for values that didn’t come from one: numbers typed by hand, and GTINs carried inside another barcode type such as a QR code. The algorithm is explained in Check digits.
Length
.validate(.length(13)).validate(.length(8...14))
Rejects values that aren’t the given length, or within the given range.Fix the length whenever you can for types with no check digit, such as Interleaved 2 of 5. It’s the main defense against a partial read, where the scanner sees only part of the barcode and reports a shorter, valid-looking number.
Pattern
.validate(.matches(/^LOC-\d{4}$/))
Rejects values that don’t match a regular expression. Use it for your own formats: location labels, asset tags, order numbers.
GS1 structure
.validate(.gs1)
Rejects values that aren’t well-formed GS1 data: unknown Application Identifiers, fields of the wrong length, invalid dates, bad check digits inside a field. See GS1 Application Identifiers.
Your own rule
.validate { scan in AssetTag(scan.value) != nil}
Return true to accept the scan. The closure receives the normalized value and the barcode type. Use it for formats the built-in rules can’t express, such as a number with your own checksum.
Check the form of a value, not its meaning. A rule should answer “could this be an asset tag?”, not “is this the asset I expected?”.Rules run on every barcode the scanner sees, so they have to be fast: no network or database calls. And a rejection only tells the user “not accepted”. To check a scan against an order or a database, do it in your own code after the value is written, where you can say what’s wrong. See Checking for the right value.
When a scan is rejected
A rejected scan isn’t written, so the field keeps its previous value. The user is told the barcode was recognized but not accepted, in a way that depends on how they’re scanning: see Behavior by source.To respond yourself as well, add a handler:
ScanField("Product barcode", text: $gtin) .validate(.checkDigit) .onRejectedScan { scan, rule in message = "That barcode isn't a valid product number." }
The handler receives the rejected scan and the rule it failed.
Behavior by source
Source
What happens to a rejected scan
Camera
The barcode is marked in the camera view as recognized but not accepted, and the camera keeps looking. On a label with several barcodes, it settles on the one that passes.
Keyboard-style scanners
The scanner types the value and the field validates it when the scanner sends Enter. The barcode type isn’t known, so rules run on the value alone.
Typing
Validated when the user submits the field.
Checking for the right value
Validation tells you a value is well formed. It can’t tell you the user scanned the right thing: a valid barcode for the wrong product passes every rule.Check that in your own code, once the value is in your binding. There you can use your app’s data and tell the user exactly what’s wrong:
ScanField("Item", text: $gtin) .barcodeTypes(.retailProduct) .validate(.checkDigit) .onChange(of: gtin) { _, scanned in if !order.contains(scanned) { message = "That item isn't in this order." } }
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"Sparklane Docs","description":"Developer documentation for ZipZapKit, the Swift SDK for scanning barcodes in your iOS app, plus a reference to every barcode type, GS1 data and check digits, and tools to decode, check and generate barcodes.","colors":{"primary":"#111214","light":"#D4FF3F","dark":"#111214"},"logo":{"light":"https://mintcdn.com/sparklane/eA0rJR6iNtLhoJwT/logo/lockup-sparklane.svg?fit=max\u0026auto=format\u0026n=eA0rJR6iNtLhoJwT\u0026q=85\u0026s=63b59b7296b0d24b4196a133ac89b8f7","dark":"https://mintcdn.com/sparklane/eA0rJR6iNtLhoJwT/logo/lockup-sparklane-dark.svg?fit=max\u0026auto=format\u0026n=eA0rJR6iNtLhoJwT\u0026q=85\u0026s=2bef0f92c77026381ca468ea149b2772","href":"https://www.sparklane.com"},"favicon":"https://mintcdn.com/sparklane/eA0rJR6iNtLhoJwT/favicon.svg?fit=max\u0026auto=format\u0026n=eA0rJR6iNtLhoJwT\u0026q=85\u0026s=f64a1c06ac831ebe08606c30a820e1a6","background":{"color":{"light":"#FAFAFA","dark":"#0E0F11"}},"navbar":{"links":[{"href":"https://www.sparklane.com/support","label":"Support"}],"primary":{"type":"button","label":"Get started","href":"/sdk/getting-started"}},"footer":{"links":[{"header":"Company","items":[{"label":"About","href":"https://www.sparklane.com/about"},{"label":"Privacy","href":"https://www.sparklane.com/privacy"},{"label":"Legal","href":"https://www.sparklane.com/legal"}]}]},"fonts":{"family":"Geist"},"styling":{"codeblocks":"dark","latex":false},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"sparklane","hasAudioNarration":false,"actualSubdomain":"sparklane","customDomains":["docs.sparklane.com"],"gitSource":{"type":"github","owner":"sparklane-inc","repo":"sparklane-docs","deployBranch":"main","contentDirectory":"","isPrivate":true,"mountPath":"","label":"","_id":"6b1102489ffae5051c41e584"},"feedback":{"thumbs":true,"agentFeedback":true},"entitlements":{"AI_CHAT":{"status":"DISABLED"},"WEB_MCP":{"status":"DISABLED"},"NARRATION":{"status":"DISABLED"}},"buildId":"6ac46c4478efa927eac3ad34","clientVersion":"0.0.4428","searchFilterCounts":[{"language":"default","tag":"Barcode reference","count":47},{"language":"default","tag":"SDK","count":17},{"language":"default","tag":"Logistics and industrial","count":12},{"language":"default","tag":"Postal","count":10},{"language":"default","tag":"2D","count":9},{"language":"default","tag":"Retail (GTIN)","count":8},{"language":"default","tag":"Reference","count":7},{"language":"default","tag":"API reference","count":5},{"language":"default","tag":"Tools","count":4},{"language":"default","tag":"Modifiers","count":3}]},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":false,"enableContextualStarterQuestions":false,"enableAskAiSearchBar":true},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"starter-pricing","enabled":true,"variant":{"name":"treatment","enabled":true,"payload":{"type":"string","value":"treatment"},"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"auth-vite-origin","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"starterQuestions":[],"googleFontsInlined":true},"customCss":[{"filePath":"style.css","content":"/* cyrillic-ext */\n@font-face {\n font-family: 'JetBrains Mono';\n font-style: normal;\n font-weight: 400;\n font-display: swap;\n src: url(/_mintlify/assets/fonts/google/s/jetbrainsmono/v24/tDbY2o-flEEny0FZhsfKu5WU4zr3E_BX0PnT8RD8yKxTN1OVgaY.woff2) format('woff2');\n unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;\n}\n/* cyrillic */\n@font-face {\n font-family: 'JetBrains Mono';\n font-style: normal;\n font-weight: 400;\n font-display: swap;\n src: url(/_mintlify/assets/fonts/google/s/jetbrainsmono/v24/tDbY2o-flEEny0FZhsfKu5WU4zr3E_BX0PnT8RD8yKxTPlOVgaY.woff2) format('woff2');\n unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;\n}\n/* greek */\n@font-face {\n font-family: 'JetBrains Mono';\n font-style: normal;\n font-weight: 400;\n font-display: swap;\n src: url(/_mintlify/assets/fonts/google/s/jetbrainsmono/v24/tDbY2o-flEEny0FZhsfKu5WU4zr3E_BX0PnT8RD8yKxTOVOVgaY.woff2) format('woff2');\n unicode-range: U+0370-0377, U+037A-037F, U+0384-038A, U+038C, U+038E-03A1, U+03A3-03FF;\n}\n/* vietnamese */\n@font-face {\n font-family: 'JetBrains Mono';\n font-style: normal;\n font-weight: 400;\n font-display: swap;\n src: url(/_mintlify/assets/fonts/google/s/jetbrainsmono/v24/tDbY2o-flEEny0FZhsfKu5WU4zr3E_BX0PnT8RD8yKxTNVOVgaY.woff2) format('woff2');\n unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;\n}\n/* latin-ext */\n@font-face {\n font-family: 'JetBrains Mono';\n font-style: normal;\n font-weight: 400;\n font-display: swap;\n src: url(/_mintlify/assets/fonts/google/s/jetbrainsmono/v24/tDbY2o-flEEny0FZhsfKu5WU4zr3E_BX0PnT8RD8yKxTNFOVgaY.woff2) format('woff2');\n unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;\n}\n/* latin */\n@font-face {\n font-family: 'JetBrains Mono';\n font-style: normal;\n font-weight: 400;\n font-display: swap;\n src: url(/_mintlify/assets/fonts/google/s/jetbrainsmono/v24/tDbY2o-flEEny0FZhsfKu5WU4zr3E_BX0PnT8RD8yKxTOlOV.woff2) format('woff2');\n unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;\n}\n:root{--sl-line: #E4E6EA;--sl-ink-muted: #6B6F76;--sl-surface: #F2F3F5}.dark{--sl-line: #1E2023;--sl-ink-muted: #9A9EA6;--sl-surface: #17181B}code,pre,kbd,samp{font-family:\"JetBrains Mono\", ui-monospace, SFMono-Regular, Menlo, monospace}h1,h2,h3{font-weight:700;letter-spacing:-0.03em;text-wrap:pretty}h1{letter-spacing:-0.04em}[data-table-wrapper] [data-component-part=\"scroll-area-viewport\"]{--table-cover: rgb(var(--background-light));--table-cover-clear: rgb(var(--background-light) / 0);--table-shadow: rgb(0 0 0 / 0.28);background:linear-gradient(to right, var(--table-cover) 30%, var(--table-cover-clear)) left center / 40px 100% no-repeat local,\n linear-gradient(to left, var(--table-cover) 30%, var(--table-cover-clear)) right center / 40px 100% no-repeat local,\n radial-gradient(farthest-side at 0 50%, var(--table-shadow), transparent) left center / 20px 100% no-repeat scroll,\n radial-gradient(farthest-side at 100% 50%, var(--table-shadow), transparent) right center / 20px 100% no-repeat scroll}.dark [data-table-wrapper] [data-component-part=\"scroll-area-viewport\"]{--table-cover: rgb(var(--background-dark));--table-cover-clear: rgb(var(--background-dark) / 0);--table-shadow: rgb(255 255 255 / 0.22)}@media (max-width: 640px){[data-table-wrapper] table td,[data-table-wrapper] table th{min-width:0}}.barcode-tool table{border-collapse:collapse;margin:12px 0;font-size:14px}.barcode-tool th,.barcode-tool td{padding:6px 16px 6px 0;text-align:left;vertical-align:top}.barcode-tool th:last-child,.barcode-tool td:last-child{padding-right:0}.barcode-tool tr+tr>*,.barcode-tool tbody tr:first-child>*{border-top:1px solid rgb(128 128 128 / 0.25)}.barcode-tool .viewer-close{background:rgb(255 255 255 / 0.72);color:#111214}.dark .barcode-tool .viewer-close{background:rgb(14 15 17 / 0.62);color:#fff}"}]}
{"page":{"pagePath":"sdk/modifiers/validation","slug":"/sdk/modifiers/validation","pageMetadata":{"title":"Validation","description":"Reject scans that don't match what a ScanField expects, before they reach your data.","href":"/sdk/modifiers/validation"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Reject scans that don’t match what a ScanField expects, before they reach your data.\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,li:`li`,ol:`ol`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,tbody:`tbody`,td:`td`,th:`th`,thead:`thead`,tr:`tr`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,Heading,Table,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Table)_missingMdxReference(`Table`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsx(Warning,{children:`ZipZapKit hasn’t been released yet. The API names on this page are provisional and may change.`}),`\n`,_jsx(_components.p,{children:`Validation checks each scan against rules you set and rejects the ones that fail. A rejected scan never reaches your binding, so your app only ever sees values it can use.`}),`\n`,_jsx(_components.p,{children:`Use it when a wrong scan is likely or costly: labels with several barcodes on them, numbers that people sometimes type by hand, or fields where a bad value causes trouble later.`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`3`,language:`swift`,children:_jsx(_components.pre,{className:`shiki shiki-themes dark-plus dark-plus`,style:{backgroundColor:`#0B0C0E`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},language:`swift`,children:_jsxs(_components.code,{language:`swift`,numberOfLines:`3`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`ScanField`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`\"Product barcode\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`text`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`: $gtin)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` .`}),_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`barcodeTypes`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`(.`}),_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:`retailProduct`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` .`}),_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`validate`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`(.`}),_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:`checkDigit`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`This field accepts retail product barcodes and rejects any value whose check digit is wrong.`}),`\n`,_jsx(Heading,{level:`2`,id:`how-it-works`,children:`How it works`}),`\n`,_jsx(_components.p,{children:`Every scan goes through the same steps, in this order:`}),`\n`,_jsxs(_components.ol,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Barcode type.`}),` Is this one of the types the field accepts? See `,_jsx(_components.a,{href:`/sdk/modifiers/barcode-types`,children:`Barcode types`}),`.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Normalization.`}),` The value is converted to the form you asked for. See `,_jsx(_components.a,{href:`/sdk/modifiers/normalization`,children:`Normalization`}),`.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Validation.`}),` Each rule checks the normalized value.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Your binding.`}),` If every rule passes, the value is written.`]}),`\n`]}),`\n`,_jsx(_components.p,{children:`Because validation runs after normalization, write your rules for the form you store. If you normalize to 14-digit GTINs, validate 14 digits.`}),`\n`,_jsx(_components.p,{children:`Barcode types and validation answer different questions. Barcode types decide which barcodes are read at all. Validation decides whether what was read is acceptable.`}),`\n`,_jsx(Heading,{level:`2`,id:`rules`,children:`Rules`}),`\n`,_jsxs(_components.p,{children:[`Add one `,_jsx(_components.code,{children:`.validate`}),` modifier for each rule. A scan has to pass all of them.`]}),`\n`,_jsx(Heading,{level:`3`,id:`check-digit`,children:`Check digit`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`swift`,children:_jsx(_components.pre,{className:`shiki shiki-themes dark-plus dark-plus`,style:{backgroundColor:`#0B0C0E`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},language:`swift`,children:_jsxs(_components.code,{language:`swift`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`validate`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`(.`}),_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:`checkDigit`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`Recalculates the check digit and rejects the value if it doesn’t match. It applies to GTINs (UPC-A, UPC-E, EAN-13, EAN-8, ITF-14) and passes other values through.`}),`\n`,_jsxs(_components.p,{children:[`A scanner already verifies the check digit of a UPC or EAN while reading it, so this rule matters most for values that didn’t come from one: numbers typed by hand, and GTINs carried inside another barcode type such as a QR code. The algorithm is explained in `,_jsx(_components.a,{href:`/reference/check-digits`,children:`Check digits`}),`.`]}),`\n`,_jsx(Heading,{level:`3`,id:`length`,children:`Length`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`2`,language:`swift`,children:_jsx(_components.pre,{className:`shiki shiki-themes dark-plus dark-plus`,style:{backgroundColor:`#0B0C0E`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},language:`swift`,children:_jsxs(_components.code,{language:`swift`,numberOfLines:`2`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`validate`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`(.`}),_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`length`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#B5CEA8`,\"--shiki-dark\":`#B5CEA8`},children:`13`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`))`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`validate`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`(.`}),_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`length`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#B5CEA8`,\"--shiki-dark\":`#B5CEA8`},children:`8`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`...`}),_jsx(_components.span,{style:{color:`#B5CEA8`,\"--shiki-dark\":`#B5CEA8`},children:`14`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`))`})]}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`Rejects values that aren’t the given length, or within the given range.`}),`\n`,_jsxs(_components.p,{children:[`Fix the length whenever you can for types with no check digit, such as `,_jsx(_components.a,{href:`/reference/barcode-types/interleaved-2-of-5`,children:`Interleaved 2 of 5`}),`. It’s the main defense against a partial read, where the scanner sees only part of the barcode and reports a shorter, valid-looking number.`]}),`\n`,_jsx(Heading,{level:`3`,id:`pattern`,children:`Pattern`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`swift`,children:_jsx(_components.pre,{className:`shiki shiki-themes dark-plus dark-plus`,style:{backgroundColor:`#0B0C0E`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},language:`swift`,children:_jsxs(_components.code,{language:`swift`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`validate`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`(.`}),_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`matches`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#D16969`,\"--shiki-dark\":`#D16969`},children:`/`}),_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`^`}),_jsx(_components.span,{style:{color:`#D16969`,\"--shiki-dark\":`#D16969`},children:`LOC-\\\\d`}),_jsx(_components.span,{style:{color:`#D7BA7D`,\"--shiki-dark\":`#D7BA7D`},children:`{4}`}),_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`$`}),_jsx(_components.span,{style:{color:`#D16969`,\"--shiki-dark\":`#D16969`},children:`/`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`))`})]}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`Rejects values that don’t match a regular expression. Use it for your own formats: location labels, asset tags, order numbers.`}),`\n`,_jsx(Heading,{level:`3`,id:`gs1-structure`,children:`GS1 structure`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`swift`,children:_jsx(_components.pre,{className:`shiki shiki-themes dark-plus dark-plus`,style:{backgroundColor:`#0B0C0E`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},language:`swift`,children:_jsxs(_components.code,{language:`swift`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`validate`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`(.`}),_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:`gs1`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`Rejects values that aren’t well-formed GS1 data: unknown Application Identifiers, fields of the wrong length, invalid dates, bad check digits inside a field. See `,_jsx(_components.a,{href:`/sdk/gs1/application-identifiers`,children:`GS1 Application Identifiers`}),`.`]}),`\n`,_jsx(Heading,{level:`3`,id:`your-own-rule`,children:`Your own rule`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`3`,language:`swift`,children:_jsx(_components.pre,{className:`shiki shiki-themes dark-plus dark-plus`,style:{backgroundColor:`#0B0C0E`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},language:`swift`,children:_jsxs(_components.code,{language:`swift`,numberOfLines:`3`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`validate`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` { scan `}),_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:`in`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:` AssetTag`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`(scan.`}),_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:`value`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`) != `}),_jsx(_components.span,{style:{color:`#569CD6`,\"--shiki-dark\":`#569CD6`},children:`nil`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`Return `,_jsx(_components.code,{children:`true`}),` to accept the scan. The closure receives the normalized value and the barcode type. Use it for formats the built-in rules can’t express, such as a number with your own checksum.`]}),`\n`,_jsxs(Warning,{children:[_jsxs(_components.p,{children:[_jsx(_components.strong,{children:`Check the form of a value, not its meaning.`}),` A rule should answer “could this be an asset tag?”, not “is this the asset I expected?”.`]}),_jsxs(_components.p,{children:[`Rules run on every barcode the scanner sees, so they have to be fast: no network or database calls. And a rejection only tells the user “not accepted”. To check a scan against an order or a database, do it in your own code after the value is written, where you can say what’s wrong. See `,_jsx(_components.a,{href:`#checking-for-the-right-value`,children:`Checking for the right value`}),`.`]})]}),`\n`,_jsx(Heading,{level:`2`,id:`when-a-scan-is-rejected`,children:`When a scan is rejected`}),`\n`,_jsxs(_components.p,{children:[`A rejected scan isn’t written, so the field keeps its previous value. The user is told the barcode was recognized but not accepted, in a way that depends on how they’re scanning: see `,_jsx(_components.a,{href:`#behavior-by-source`,children:`Behavior by source`}),`.`]}),`\n`,_jsx(_components.p,{children:`To respond yourself as well, add a handler:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`5`,language:`swift`,children:_jsx(_components.pre,{className:`shiki shiki-themes dark-plus dark-plus`,style:{backgroundColor:`#0B0C0E`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},language:`swift`,children:_jsxs(_components.code,{language:`swift`,numberOfLines:`5`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`ScanField`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`\"Product barcode\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`text`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`: $gtin)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` .`}),_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`validate`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`(.`}),_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:`checkDigit`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` .`}),_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`onRejectedScan`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` { scan, rule `}),_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:`in`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` message = `}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`\"That barcode isn't a valid product number.\"`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`The handler receives the rejected scan and the rule it failed.`}),`\n`,_jsx(Heading,{level:`2`,id:`behavior-by-source`,children:`Behavior by source`}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Source`}),_jsx(_components.th,{children:`What happens to a rejected scan`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Camera`}),_jsx(_components.td,{children:`The barcode is marked in the camera view as recognized but not accepted, and the camera keeps looking. On a label with several barcodes, it settles on the one that passes.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Keyboard-style scanners`}),_jsx(_components.td,{children:`The scanner types the value and the field validates it when the scanner sends Enter. The barcode type isn’t known, so rules run on the value alone.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Typing`}),_jsx(_components.td,{children:`Validated when the user submits the field.`})]})]})]}),`\n`,_jsx(Heading,{level:`2`,id:`checking-for-the-right-value`,children:`Checking for the right value`}),`\n`,_jsx(_components.p,{children:`Validation tells you a value is well formed. It can’t tell you the user scanned the right thing: a valid barcode for the wrong product passes every rule.`}),`\n`,_jsx(_components.p,{children:`Check that in your own code, once the value is in your binding. There you can use your app’s data and tell the user exactly what’s wrong:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`8`,language:`swift`,children:_jsx(_components.pre,{className:`shiki shiki-themes dark-plus dark-plus`,style:{backgroundColor:`#0B0C0E`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},language:`swift`,children:_jsxs(_components.code,{language:`swift`,numberOfLines:`8`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`ScanField`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`\"Item\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`text`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`: $gtin)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` .`}),_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`barcodeTypes`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`(.`}),_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:`retailProduct`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` .`}),_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`validate`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`(.`}),_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:`checkDigit`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` .`}),_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`onChange`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`of`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`: gtin) { `}),_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:`_`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`, scanned `}),_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:`in`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` !order.`}),_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`contains`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`(scanned) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` message = `}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`\"That item isn't in this order.\"`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`related`,children:`Related`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.a,{href:`/sdk/modifiers/barcode-types`,children:`Barcode types`}),`: choose which barcodes a field reads.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.a,{href:`/sdk/modifiers/normalization`,children:`Normalization`}),`: convert scans to one form before validating.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.a,{href:`/reference/check-digits`,children:`Check digits`}),`: how each check digit is calculated.`]}),`\n`,_jsx(_components.li,{children:_jsx(_components.a,{href:`/api-reference/modifiers`,children:`Modifiers API reference`})}),`\n`]})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"codeStyling":"dark","config":{},"pageMetadata":{"title":"Validation","description":"Reject scans that don't match what a ScanField expects, before they reach your data.","href":"/sdk/modifiers/validation"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"How it works","slug":"how-it-works","depth":2,"children":[]},{"title":"Rules","slug":"rules","depth":2,"children":[{"title":"Check digit","slug":"check-digit","depth":3,"children":[]},{"title":"Length","slug":"length","depth":3,"children":[]},{"title":"Pattern","slug":"pattern","depth":3,"children":[]},{"title":"GS1 structure","slug":"gs1-structure","depth":3,"children":[]},{"title":"Your own rule","slug":"your-own-rule","depth":3,"children":[]}]},{"title":"When a scan is rejected","slug":"when-a-scan-is-rejected","depth":2,"children":[]},{"title":"Behavior by source","slug":"behavior-by-source","depth":2,"children":[]},{"title":"Checking for the right value","slug":"checking-for-the-right-value","depth":2,"children":[]},{"title":"Related","slug":"related","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":[],"subdomain":"sparklane","siteName":"Sparklane Docs","title":"Validation - Sparklane Docs","contextualStarterQuestions":[],"navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-10-06T03:35:02.823Z","originalFileLocation":"sdk/modifiers/validation.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Reject scans that don\u0026#x27;t match what a ScanField expects, before they reach your data.\">\u003cmeta data-mint-head name=\"application-name\" content=\"Sparklane Docs\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/sparklane/Qyp4_kXo-HltD2Eb/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/sparklane/Qyp4_kXo-HltD2Eb/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/sparklane/Qyp4_kXo-HltD2Eb/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/sparklane/Qyp4_kXo-HltD2Eb/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/sparklane/Qyp4_kXo-HltD2Eb/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/sparklane/Qyp4_kXo-HltD2Eb/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/sparklane/Qyp4_kXo-HltD2Eb/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/sparklane/Qyp4_kXo-HltD2Eb/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/sparklane/Qyp4_kXo-HltD2Eb/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Validation - Sparklane Docs\">\u003cmeta data-mint-head property=\"og:description\" content=\"Reject scans that don\u0026#x27;t match what a ScanField expects, before they reach your data.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Sparklane Docs\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.sparklane.com/sdk/modifiers/validation\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://sparklane.mintlify.site/_mintlify/api/og/v2?division=Modifiers\u0026amp;title=Validation\u0026amp;description=Reject+scans+that+don%27t+match+what+a+ScanField+expects%2C+before+they+reach+your+data.\u0026amp;theme=f4dacdeea88096d3fd6c053b\u0026amp;signature=b4ec7beb8836a53c629cf3eeb5ecb7ef42f96fb34a0b70d4a0fef50c9559a063\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Validation - Sparklane Docs\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Reject scans that don\u0026#x27;t match what a ScanField expects, before they reach your data.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://sparklane.mintlify.site/_mintlify/api/og/v2?division=Modifiers\u0026amp;title=Validation\u0026amp;description=Reject+scans+that+don%27t+match+what+a+ScanField+expects%2C+before+they+reach+your+data.\u0026amp;theme=f4dacdeea88096d3fd6c053b\u0026amp;signature=b4ec7beb8836a53c629cf3eeb5ecb7ef42f96fb34a0b70d4a0fef50c9559a063\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/sparklane/Qyp4_kXo-HltD2Eb/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Sparklane Docs\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#111214\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.sparklane.com/sdk/modifiers/validation\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/sdk/modifiers/validation.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.sparklane.com/#organization\",\"name\":\"Sparklane Docs\",\"url\":\"https://docs.sparklane.com\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/sparklane/eA0rJR6iNtLhoJwT/logo/lockup-sparklane.svg?fit=max\u0026auto=format\u0026n=eA0rJR6iNtLhoJwT\u0026q=85\u0026s=63b59b7296b0d24b4196a133ac89b8f7\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.sparklane.com#website\",\"name\":\"Sparklane Docs\",\"url\":\"https://docs.sparklane.com\",\"publisher\":{\"@id\":\"https://docs.sparklane.com/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.sparklane.com/sdk/modifiers/validation#webpage\",\"url\":\"https://docs.sparklane.com/sdk/modifiers/validation\",\"name\":\"Validation\",\"description\":\"Reject scans that don't match what a ScanField expects, before they reach your data.\",\"dateModified\":\"2026-10-06T03:35:02.823Z\",\"isPartOf\":{\"@id\":\"https://docs.sparklane.com#website\"},\"breadcrumb\":{\"@id\":\"https://docs.sparklane.com/sdk/modifiers/validation#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.sparklane.com/sdk/modifiers/validation#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Modifiers\",\"item\":\"https://docs.sparklane.com/sdk/modifiers/barcode-types\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Validation\",\"item\":\"https://docs.sparklane.com/sdk/modifiers/validation\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.sparklane.com/sdk/modifiers/validation#article\",\"headline\":\"Validation\",\"name\":\"Validation\",\"description\":\"Reject scans that don't match what a ScanField expects, before they reach your data.\",\"url\":\"https://docs.sparklane.com/sdk/modifiers/validation\",\"mainEntityOfPage\":{\"@id\":\"https://docs.sparklane.com/sdk/modifiers/validation#webpage\"},\"dateModified\":\"2026-10-06T03:35:02.823Z\",\"publisher\":{\"@id\":\"https://docs.sparklane.com/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.sparklane.com#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Sparklane Docs\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"Sparklane Docs\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/sdk/modifiers/validation.md","siteName":"Sparklane Docs","nav":{"global":null,"tabs":[{"tab":"SDK","groups":[{"group":"Get started","pages":[{"title":"Sparklane docs","icon":"house","href":""},{"title":"Getting started","icon":"rocket","href":"/sdk/getting-started"}]},{"group":"ScanField","pages":[{"title":"Replacing a TextField","sidebarTitle":"Replacing a TextField","href":"/sdk/scanfield/replacing-a-textfield"},{"title":"Scan sources","href":"/sdk/scanfield/sources"}]},{"group":"Modifiers","pages":[{"title":"Barcode types","description":"Restrict which barcode types a ScanField accepts.","href":"/sdk/modifiers/barcode-types"},{"title":"Validation","href":"/sdk/modifiers/validation"},{"title":"Normalization","description":"Canonicalize scanned values before they reach your binding.","href":"/sdk/modifiers/normalization"}]},{"group":"GS1","pages":[{"title":"GS1 Application Identifiers","href":"/sdk/gs1/application-identifiers"},{"title":"GS1 Digital Link","href":"/sdk/gs1/digital-link"}]},{"group":"Migrate","pages":[{"title":"Migrating from Scandit","icon":"right-left","href":"/sdk/migrating-from-scandit"}]},{"group":"API reference","pages":[{"title":"API reference","icon":"code","href":"/api-reference/overview"},{"title":"ScanField","href":"/api-reference/scanfield"},{"title":"Modifiers","href":"/api-reference/modifiers"},{"title":"Sources","href":"/api-reference/sources"},{"title":"GS1 parsing","href":"/api-reference/gs1"}]},{"group":"Project","pages":[{"title":"Changelog","icon":"clock-rotate-left","href":"/changelog"},{"title":"License","icon":"scale-balanced","href":"/license"}]}]},{"tab":"Tools","pages":[{"title":"Tools","href":"/tools/barcode-anatomy"}]},{"tab":"Barcode reference","pages":[{"title":"Barcode reference","href":"/reference/overview"}]}]},"basePath":"","title":"Validation - Sparklane Docs","deploymentId":"dpl_4dgnk6TA5fUgboKHTvWWyeqm3idh","buildId":"dpl_4dgnk6TA5fUgboKHTvWWyeqm3idh","dynamics":[],"chunks":[]}