diff --git a/src/pages/iou/steps/MoneyRequestAmountPage.js b/src/pages/iou/steps/MoneyRequestAmountPage.js index 10c260895490..7fb169fa3d84 100755 --- a/src/pages/iou/steps/MoneyRequestAmountPage.js +++ b/src/pages/iou/steps/MoneyRequestAmountPage.js @@ -59,6 +59,7 @@ class MoneyRequestAmountPage extends React.Component { this.updateLongPressHandlerState = this.updateLongPressHandlerState.bind(this); this.updateAmount = this.updateAmount.bind(this); this.stripCommaFromAmount = this.stripCommaFromAmount.bind(this); + this.stripSpacesFromAmount = this.stripSpacesFromAmount.bind(this); this.focusTextInput = this.focusTextInput.bind(this); this.navigateToCurrencySelectionPage = this.navigateToCurrencySelectionPage.bind(this); this.amountViewID = 'amountView'; @@ -126,13 +127,16 @@ class MoneyRequestAmountPage extends React.Component { * @returns {Object} */ getNewState(prevState, newAmount) { - if (!this.validateAmount(newAmount)) { + // Remove spaces from the newAmount value because Safari on iOS adds spaces when pasting a copied value + // More info: https://github.com/Expensify/App/issues/16974 + const newAmountWithoutSpaces = this.stripSpacesFromAmount(newAmount); + if (!this.validateAmount(newAmountWithoutSpaces)) { // Use a shallow copy of selection to trigger setSelection // More info: https://github.com/Expensify/App/issues/16385 return {amount: prevState.amount, selection: {...prevState.selection}}; } - const selection = this.getNewSelection(prevState.selection, prevState.amount.length, newAmount.length); - return {amount: this.stripCommaFromAmount(newAmount), selection}; + const selection = this.getNewSelection(prevState.selection, prevState.amount.length, newAmountWithoutSpaces.length); + return {amount: this.stripCommaFromAmount(newAmountWithoutSpaces), selection}; } /** @@ -194,6 +198,16 @@ class MoneyRequestAmountPage extends React.Component { return amount.replace(/,/g, ''); } + /** + * Strip spaces from the amount + * + * @param {String} amount + * @returns {String} + */ + stripSpacesFromAmount(amount) { + return amount.replace(/\s+/g, ''); + } + /** * Adds a leading zero to the amount if user entered just the decimal separator *