Skip to content

Fix Update regex for masked accountNumber #30813

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
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
5 changes: 2 additions & 3 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,8 @@ const CONST = {
REGEX: {
US_ACCOUNT_NUMBER: /^[0-9]{4,17}$/,

// If the account number length is from 4 to 13 digits, we show the last 4 digits and hide the rest with X
// If the length is longer than 13 digits, we show the first 6 and last 4 digits, hiding the rest with X
MASKED_US_ACCOUNT_NUMBER: /^[X]{0,9}[0-9]{4}$|^[0-9]{6}[X]{4,7}[0-9]{4}$/,
// The back-end is always returning account number with 4 last digits and mask the rest with X
MASKED_US_ACCOUNT_NUMBER: /^[X]{0,13}[0-9]{4}$/,
SWIFT_BIC: /^[A-Za-z0-9]{8,11}$/,
},
VERIFICATION_MAX_ATTEMPTS: 7,
Expand Down
9 changes: 5 additions & 4 deletions src/pages/ReimbursementAccount/BankAccountManualStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const propTypes = {
function BankAccountManualStep(props) {
const {translate, preferredLocale} = useLocalize();
const {reimbursementAccount, reimbursementAccountDraft} = props;

const shouldDisableInputs = Boolean(lodashGet(reimbursementAccount, 'achData.bankAccountID'));

/**
* @param {Object} values - form input values passed by the Form component
* @returns {Object}
Expand All @@ -40,7 +43,7 @@ function BankAccountManualStep(props) {
if (
values.accountNumber &&
!CONST.BANK_ACCOUNT.REGEX.US_ACCOUNT_NUMBER.test(values.accountNumber.trim()) &&
!CONST.BANK_ACCOUNT.REGEX.MASKED_US_ACCOUNT_NUMBER.test(values.accountNumber.trim())
!(shouldDisableInputs && CONST.BANK_ACCOUNT.REGEX.MASKED_US_ACCOUNT_NUMBER.test(values.accountNumber.trim()))
) {
errors.accountNumber = 'bankAccount.error.accountNumber';
} else if (values.accountNumber && values.accountNumber === routingNumber) {
Expand All @@ -55,7 +58,7 @@ function BankAccountManualStep(props) {

return errors;
},
[translate],
[translate, shouldDisableInputs],
);

const submit = useCallback(
Expand All @@ -70,8 +73,6 @@ function BankAccountManualStep(props) {
[reimbursementAccount, reimbursementAccountDraft],
);

const shouldDisableInputs = Boolean(lodashGet(reimbursementAccount, 'achData.bankAccountID'));

return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
Expand Down