/** * Parse the raw text of a stock-form Quantity field. * * The text is kept exactly as typed so the user sees what they entered. Anything that is not * plain digits ("1.5", "1e5", "-3") is NOT rewritten into a different number: its quantity is 0, * which the forms' "at least 1" validation rejects on Submit until the user corrects it. */ export function parseQuantityInput(text: string): { quantityText: string; quantity: number } { if (!/^\d*$/.test(text)) return { quantityText: text, quantity: 0 }; return { quantityText: text, quantity: text === "" ? 0 : parseInt(text, 10) }; }