diff --git a/src/pages/iou/steps/IOUAmountPage.js b/src/pages/iou/steps/IOUAmountPage.js index c1b42042e108..28ca5c68034c 100755 --- a/src/pages/iou/steps/IOUAmountPage.js +++ b/src/pages/iou/steps/IOUAmountPage.js @@ -127,6 +127,16 @@ class IOUAmountPage extends React.Component { return amount.replace(/,/g, ''); } + /** + * Adds a leading zero to the amount if user entered just the decimal separator + * + * @param {String} amount - Changed amount from user input + * @returns {String} + */ + addLeadingZero(amount) { + return amount === '.' ? '0.' : amount; + } + /** * Update amount with number or Backspace pressed for BigNumberPad. * Validate new amount with decimal number regex up to 6 digits and 2 decimal digit to enable Next button @@ -145,7 +155,7 @@ class IOUAmountPage extends React.Component { } this.setState((prevState) => { - const amount = `${prevState.amount}${key}`; + const amount = this.addLeadingZero(`${prevState.amount}${key}`); return this.validateAmount(amount) ? {amount: this.stripCommaFromAmount(amount)} : prevState; }); } @@ -158,7 +168,7 @@ class IOUAmountPage extends React.Component { */ updateAmount(text) { this.setState((prevState) => { - const amount = this.replaceAllDigits(text, this.props.fromLocaleDigit); + const amount = this.addLeadingZero(this.replaceAllDigits(text, this.props.fromLocaleDigit)); return this.validateAmount(amount) ? {amount: this.stripCommaFromAmount(amount)} : prevState;