From d124f35a3ed6bb3378eb40a42ba6fd6156aca287 Mon Sep 17 00:00:00 2001 From: Mifas Date: Tue, 13 Nov 2018 10:18:03 +0800 Subject: [PATCH 1/2] converting fullwidth numbers to halfwidth --- src/number_format.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/number_format.js b/src/number_format.js index 14b8cfe0..1e598bef 100644 --- a/src/number_format.js +++ b/src/number_format.js @@ -359,6 +359,23 @@ class NumberFormat extends React.Component { } /** caret specific methods ends **/ + convertFullwidthToHalfwidth = (val: string) => { + let ascii = ''; + for(let i=0, l=val.length; i= 65296 && c<= 65305) || (c>=48 && c<=57) ){ + // make sure we only convert half-full width char + if (c >= 0xFF00 && c <= 0xFFEF) { + c = 0xFF & (c + 0x20); + } + ascii += String.fromCharCode(c); + } + } + return ascii + } /** methods to remove formattting **/ removePrefixAndSuffix(val: string) { @@ -603,6 +620,8 @@ class NumberFormat extends React.Component { const {selectionStart, selectionEnd} = this.selectionBeforeInput; const {start, end} = findChangedIndex(lastValue, value); + value = this.convertFullwidthToHalfwidth(value) + /** Check if only . is added in the numeric format and replace it with decimal separator */ if (!format && decimalSeparator !== '.' && start === end && value[selectionStart] === '.') { return value.substr(0, selectionStart) + decimalSeparator + value.substr(selectionStart + 1, value.length); From 674c6f54af3cd27ae40bb5c9a4e579b294a792c8 Mon Sep 17 00:00:00 2001 From: Mifas Date: Tue, 13 Nov 2018 10:32:56 +0800 Subject: [PATCH 2/2] removed charachter range --- src/number_format.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/number_format.js b/src/number_format.js index 1e598bef..486e15ad 100644 --- a/src/number_format.js +++ b/src/number_format.js @@ -363,16 +363,11 @@ class NumberFormat extends React.Component { let ascii = ''; for(let i=0, l=val.length; i= 65296 && c<= 65305) || (c>=48 && c<=57) ){ - // make sure we only convert half-full width char - if (c >= 0xFF00 && c <= 0xFFEF) { - c = 0xFF & (c + 0x20); - } - ascii += String.fromCharCode(c); + // make sure we only convert half-full width char + if (c >= 0xFF00 && c <= 0xFFEF) { + c = 0xFF & (c + 0x20); } + ascii += String.fromCharCode(c); } return ascii }