Files
fendi-react-app/src/utils/validation.jsx
2025-06-10 21:26:42 -06:00

12 lines
434 B
JavaScript

export function handleDecimalInputKeyDown(e) {
const allowedKeys = ['Backspace', 'Tab', 'Delete', 'ArrowLeft', 'ArrowRight'];
const isDigit = /^[0-9]$/.test(e.key);
const isDot = e.key === '.';
const currentValue = e.target.value ?? '';
const alreadyHasDot = currentValue.includes('.');
if (allowedKeys.includes(e.key)) return;
if (isDot && !alreadyHasDot) return;
if (!isDigit) e.preventDefault();
}