diff --git a/src/components/management/StuffDetail.jsx b/src/components/management/StuffDetail.jsx index 20332963..e0843b5d 100644 --- a/src/components/management/StuffDetail.jsx +++ b/src/components/management/StuffDetail.jsx @@ -22,7 +22,7 @@ import { stuffSearchState } from '@/store/stuffAtom' import { QcastContext } from '@/app/QcastProvider' import { useCanvasMenu } from '@/hooks/common/useCanvasMenu' import { useSwal } from '@/hooks/useSwal' -import { sanitizeDecimalInputEvent} from '@/util/input-utils' +import { sanitizeIntegerInputEvent } from '@/util/input-utils' export default function StuffDetail() { const [stuffSearch, setStuffSearch] = useRecoilState(stuffSearchState) diff --git a/src/util/input-utils.js b/src/util/input-utils.js index a4376430..7578e95e 100644 --- a/src/util/input-utils.js +++ b/src/util/input-utils.js @@ -24,15 +24,38 @@ export const onlyNumberWithDotInputChange = (e, callback) => { // Number normalization utilities // ============================= // 1) Normalize any string to NFKC and keep only ASCII digits 0-9. +// 1) Normalize any string to keep only ASCII digits 0-9 export function normalizeDigits(value) { - return String(value ?? '').normalize('NFKC').replace(/[^0-9]/g, '') + if (value == null) return ''; + + // First convert full-width numbers to half-width + const str = String(value).replace(/[0-9]/g, s => + String.fromCharCode(s.charCodeAt(0) - 0xFEE0) + ); + + // Then remove all non-digit characters + return str.replace(/\D/g, ''); } -// 2) Normalize decimal numbers (allow one dot). +// 2) Normalize decimal numbers (allow one dot) export function normalizeDecimal(value) { - const s = String(value ?? '').normalize('NFKC').replace(/[^0-9.]/g, '') - const [head, ...rest] = s.split('.') - return rest.length ? `${head}.${rest.join('').replace(/\./g, '')}` : head + if (value == null) return ''; + + // Convert full-width numbers and dot to half-width + let str = String(value).replace(/[0-9.]/g, s => + s === '.' ? '.' : String.fromCharCode(s.charCodeAt(0) - 0xFEE0) + ); + + // Handle multiple dots by keeping only the first one + const parts = str.split('.'); + if (parts.length > 1) { + str = parts[0] + '.' + parts.slice(1).join(''); + } + + // Remove any remaining non-digit and non-dot characters + // and ensure only one dot remains + return str.replace(/[^\d.]/g, '') + .replace(/^(\d*\.\d*).*$/, '$1'); } // 2-1) Limit fractional digits for decimal numbers. Default to 2 digits.