How to Validate a Date Range Cross Field
Validate that a start date is before an end date using a cross-field schema, so the rule lives in the schema and the UI can show the error on either field.
Step-by-step guides and in-depth articles to level up your skills.
Page 2 of 9
Validate that a start date is before an end date using a cross-field schema, so the rule lives in the schema and the UI can show the error on either field.
Validate cascading select dropdowns where the child options depend on the parent value, so an orphan child value is rejected at the boundary.
Validate email addresses with a pragmatic regex and a DNS MX hint, so format errors are caught instantly and non-deliverable domains are flagged async.
Build a Zod enum from a runtime config array so the schema stays in sync with the config, and unknown values are rejected without a code deploy.
Check file size and type before uploading so oversized or unsupported files are rejected on the client without wasting bandwidth.
Validate image dimensions on upload with sharp so avatars are square and banners are wide, and non-conforming images are rejected before storage.
Validate that a number falls within a range and aligns to a step, so quantity inputs reject fractional steps and out-of-range values at the boundary.
Validate an OIDC ID token server side so the claims are verified against the issuer, and the nonce prevents replay.
Validate the Origin header against an allowlist so only trusted sites can make cross-origin requests, and CSRF is prevented.
Validate phone numbers in E.164 format with libphonenumber, so international numbers are normalized and invalid lengths are rejected before SMS send.
Use useFieldArray to validate dynamic lists of inputs in React Hook Form, so append, remove, and swap preserve the validation state of each row.
Validate the upload content type server side by sniffing magic bytes, so a lying Content-Type header does not let a script through.
Validate URLs against an origin allowlist to prevent open redirects and SSRF, so only approved hosts are accepted for redirects and server-side fetches.
Build a useValidation composable in Vue 3 so reactive form state, errors, and validity stay in one function reusable across components.
Validate a webhook signature with HMAC so a forged webhook is rejected, and replay is prevented with a timestamp check.
Use Valibot as a lightweight schema library for tree-shakeable validation, so the bundle stays small when only a few checks run on the client.
Use Zod discriminated unions to validate payloads that share a tag field, so each variant gets its own schema and the wrong variant fails at the boundary.
Verify email ownership with a signed token link so the account is created only after the user proves control of the inbox.
Write CLI scripts that work on Windows, macOS, and Linux by avoiding shell-specific syntax and using cross-env for env vars.
Serve cached data immediately while revalidating in the background, so users see instant content that is never stale for long.
Structure a CLI into subcommands with shared global flags, per-command help, and a dispatch table so adding a command is one entry.
Let operators change config from a UI with schema validation, an audit log of who changed what, and a rollback to any prior version.
Go beyond roles to attribute-based access control where policies consider user, resource, and action attributes for fine-grained authz.
Wrap every external call in a hard timeout that rejects after a deadline, so a hung dependency cannot stall your request handler.
Report form validation errors to assistive tech with aria-live, field linking, and a focusable error summary on submit.
Chain audit entries by hashing each entry with the previous hash so any tampering with past entries is detectable on verification.
Create guided prompts with validation, default values, and arrow-key selection so users do not have to remember flag syntax.
Find and delete temporary upload files that were never finalized, using a TTL marker and a scheduled sweep that is safe to run concurrently.
Scan uploaded files for malware with ClamAV in a separate process, rejecting infected files before they reach storage.
Reject uploads that exceed a byte budget early in the stream, before they consume disk or memory, with a clear 413 response.
Generate bash and zsh completion scripts from your command tree so users get tab completion for subcommands and flag values.
Create multiple thumbnail sizes from an uploaded image with sharp, streaming the source and writing outputs in parallel.
Let users upload many files at once without overwhelming the server, using a bounded concurrency pool and per-file error isolation.
Process duplicate events without side effects by checking an event ID ledger before applying, so redelivery is safe and cheap.
Manage wizard form state across steps with per-step validation, back navigation that preserves data, and a final atomic submit.
Set Secure, HttpOnly, SameSite, and a Path on every cookie, and rotate the signing key periodically so leaked cookies lose value.
Watch the config file for changes and atomically swap the in-memory config so long-running processes pick up changes without a restart.
Detect if stdout is a TTY and strip ANSI codes when it is not so a piped command produces clean text and a terminal gets color.
Set HSTS, X-Content-Type-Options, and Referrer-Policy so the browser applies its defenses without relying on CSP alone.
Generate a code verifier and challenge so a public client proves it holds the secret without sending it, blocking authorization code interception.
Add an integrity attribute with the file hash so a CDN compromise cannot swap a script the browser trusts without the hash changing.
Use Inquirer or prompts to ask for input with validation and defaults so a CLI can guide a user through setup instead of demanding flags.
Embed a fingerprint of the user agent and IP in the token so a token stolen and used from another device is rejected at verification.
Set a frame-ancestors directive so the page cannot be framed by another origin and a transparent overlay cannot trick a click.
Aggregate and shape data for one client view in a BFF so the browser makes one call and the backend fans out to the services it needs.
Trip open on failures, probe with limited traffic in half-open, and close on success so a dependency gets a chance to recover.
Merge flags, env vars, a config file, and defaults in a defined order so the user can override at the level they need.
Load commands from node_modules packages with a naming convention so a CLI extends without changes to its core and plugins ship independently.
Add a command that calls a REST endpoint, prints JSON or a table, and handles errors so the CLI is a thin client over the API.
Use Cobra to define commands, flags, and help text so a Go CLI gets a consistent structure and completion for free.
Use Click decorators to define commands and options so a Python CLI gets help, types, and context without boilerplate.
Use Clap derive macros to define args and subcommands so a Rust CLI gets parsing, validation, and help from a struct definition.
Load config, validate with a Zod schema, and return an inferred type so the rest of the code reads typed config, not any.
Build a UI that writes config changes with an author and timestamp so every change is auditable and a rollback points at a version.
Use React Hook Form with a Zod resolver to validate fields that depend on each other and surface cross-field errors in the right place.
Write a Zod refinement for a business rule that built-in validators cannot express, keep it composable, and test it with edge cases.
Compare two copies of a dataset row by row, report the diffs, and resolve so a replica that drifted is caught and corrected.
Chain validators in stages so each stage checks one concern and a failure names the stage that rejected it for a clear error.
Build a React drop zone that handles dragenter, dragover, and drop, shows visual feedback, and falls back to a file input for keyboard users.
Check each dependency in a health endpoint with a timeout and report partial health so a load balancer drains a degraded instance.
Write Express middleware that rejects on missing, malformed, or expired tokens and never lets the request through when verification fails.
Count requests in a sliding window so the limit reflects recent traffic and a burst at the boundary does not double the rate.
Refill tokens at a fixed rate and take one per request so a burst is absorbed and the long-term rate stays under the limit.
Cap the total retries per window as a fraction of requests so retries help but cannot amplify load beyond the budget.
Generate form fields, labels, and validators from a single Zod schema so adding a field means changing one type, not five components.
Expose an endpoint that checks if a token is still valid, not revoked, and has the right scope so resource servers can verify opaque tokens.
Build a form builder in TypeScript where the field config, the value type, and the error shape are all derived from one schema definition.
Check attributes of the user, the resource, and the action in a policy so a rule can express owner-only edits without enumerating every role.
Generate help from the command tree with examples so a --help flag teaches the user and the docs stay in sync with the code.
Retry with exponential backoff plus jitter and a max attempts cap so retries help without creating a synchronized retry storm.
Keep a bloom filter of revoked token IDs so a stateless JWT can be revoked before expiry without a database lookup on every request.
Cache derived data under a key that includes its source version so a change to the source invalidates the derived cache without a manual purge.
Wire an AbortController to an in-flight upload so a cancel button stops the request immediately and frees the connection for the next file.
Compare installed package names against a known list and flag near-misses so a typo installs a malicious package is caught before use.
Split a large file into fixed-size chunks on the client, upload each independently, and reassemble on the server so a retry is one chunk not the whole file.
Run a scheduled job that deletes partial uploads older than a TTL so abandoned uploads from dropped connections do not fill the disk.
Collapse identical requests at the CDN edge so a cache miss for one user serves the same response to the next thousand without hitting the origin.
Compare secrets byte by byte in constant time so a timing leak does not reveal the prefix of a token one millisecond at a time.
Parse and validate config before the service starts so a missing key crashes in the deploy, not in the first request at 3 a.m.
Debounce async field validation with AbortController so late responses never overwrite newer edits and the UI stays consistent.
Hash each record, skip hashes seen in the window, and emit the rest so a load that runs twice does not double the data.
Share the in-flight promise for the same URL so three components fetching the same data fire one request and all three get the same result.
Put only the claims the token needs for its audience, keep the lifetime short, and let the resource server re-check scopes it cannot trust.
Compare the distribution of a dataset to a baseline and flag when it shifts so a silent change in the source is caught before it corrupts the output.
Compare the token fingerprint to the request fingerprint and rotate the family when a mismatch appears so a stolen token is killed.
Watch the queue depth and CPU, and when they cross a threshold reject new work so the system degrades instead of dying.
Read the first bytes of a file and match against a magic-number table so an uploaded exe renamed to jpg is caught before it is stored.
Compare the schema of incoming data to the expected schema on every batch so a producer change that breaks the pipeline is flagged.
Publish to npm so users run the tool with npx without a global install, and pin the Node engine so the right runtime is enforced.
Push config updates to services with a watch and notify so a change propagates without a restart and all instances converge.
Route uploads to different storage backends by file type or size so large videos go to object storage and small avatars stay on the local disk.
Reject uploads over the size limit before the first byte hits the server using a Content-Length check and a streaming guard that aborts on overflow.
Validate LLM output against a JSON Schema and retry on failure so the model cannot return a shape the downstream code cannot consume.
Configure Trusted Types so an injection into a DOM sink requires a policy that sanitizes, closing the XSS vector at the browser.
Print a human message to stderr, a machine-readable line to stdout if asked, and exit with a code that scripts can branch on.
Request a short-lived credential from Vault on demand so a leaked secret expires in minutes and the blast radius of a leak is bounded.
Attach the token in a request interceptor, refresh it in a response interceptor on 401, and retry the original call so auth is transparent.
Send the If-None-Match header with the last ETag so the server returns 304 with no body and the bandwidth stays on the wire for unchanged data.
Retry with exponential backoff and jitter so a transient failure is retried but a fleet of clients does not hammer the server in sync after an outage.
Serve cached data immediately, revalidate in the background, and swap when the fresh data arrives so the user sees content without waiting.