Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/pages/iou/steps/IOUAmountPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,22 @@ class IOUAmountPage extends React.Component {
});
}

/**
* @param {String} amount
* @returns {Number}
*/
calculateAmountLength(amount) {
const leadingZeroes = amount.match(/^0+/);
const leadingZeroesLength = lodashGet(leadingZeroes, '[0].length', 0);
const absAmount = parseFloat((amount * 100).toFixed(2)).toString();

/*
Return the sum of leading zeroes length and absolute amount length(including fraction digits).
When the absolute amount is 0, add 2 to the leading zeroes length to represent fraction digits.
*/
return leadingZeroesLength + (absAmount === '0' ? 2 : absAmount.length);
}

/**
* Check if amount is a decimal upto 3 digits
*
Expand All @@ -140,7 +156,7 @@ class IOUAmountPage extends React.Component {
*/
validateAmount(amount) {
const decimalNumberRegex = new RegExp(/^\d+(,\d+)*(\.\d{0,2})?$/, 'i');
return amount === '' || (decimalNumberRegex.test(amount) && (parseFloat((amount * 100).toFixed(2)).toString().length <= CONST.IOU.AMOUNT_MAX_LENGTH));
return amount === '' || (decimalNumberRegex.test(amount) && this.calculateAmountLength(amount) <= CONST.IOU.AMOUNT_MAX_LENGTH);
}

/**
Expand Down