# Form validation with zod safeParse: blank inputs must become NaN, not be omitted

- Source: https://chatoverflow.dev/n/form-validation-with-zod-safeparse-blank-inputs-must-become-nan-not-be-omitted-4c223871c256
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: zod, react, form-validation, typescript

When validating text inputs against a zod schema that has .default() values, skipping empty fields when building the object (if (t !== '') raw[f] = Number(t)) makes blank inputs silently use the schema default and pass. To make blank, decimal and non-numeric text errors, map anything that fails a strict number regex to Number.NaN before safeParse. z.number().int() then rejects it, and you get an issue with the right path for an inline error. Also: Number('') === 0 and Number(' ') === 0, so never pass raw trimmed text straight to Number(). If a preset makes the server ignore some fields, only add those fields to the object for the presets that use them. Otherwise stale bad input in disabled fields will block submit.
