Skip to content

Commit

Permalink
Merge pull request #5149 from akshayasalvi/requestor-form-age-error
Browse files Browse the repository at this point in the history
Added validation for age in Bank Requestor Form
  • Loading branch information
pecanoro authored Sep 9, 2021
2 parents f8c6120 + 0b81112 commit ddd7f92
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ export default {
tooManyAttempts: 'Due to a high number of login attempts, this option has been temporarily disabled for 24 hours. Please try again later or manually enter details instead.',
address: 'Please enter a valid address',
dob: 'Please enter a valid date of birth',
age: 'Requestors must be over 18 years old',
ssnLast4: 'Please enter valid last 4 digits of SSN',
noDefaultDepositAccountOrDebitCardAvailable: 'Please add a default deposit bank account or debit card',
existingOwners: {
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ export default {
tooManyAttempts: 'Debido a la gran cantidad de intentos de inicio de sesión, esta opción se ha desactivado temporalmente durante 24 horas. Vuelva a intentarlo más tarde o introduzca los detalles manualmente.',
address: 'Ingrese una dirección válida',
dob: 'Ingrese una fecha de nacimiento válida',
age: 'Los solicitantes deben ser mayores de 18 años',
ssnLast4: 'Ingrese los últimos 4 dígitos del número de seguro social',
noDefaultDepositAccountOrDebitCardAvailable: 'Por favor agregue una cuenta bancaria para depósitos o una tarjeta de débito',
existingOwners: {
Expand Down
15 changes: 15 additions & 0 deletions src/libs/ValidationUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ function isValidSSNLastFour(ssnLast4) {
return CONST.REGEX.SSN_LAST_FOUR.test(ssnLast4);
}

/**
*
* @param {String} date
* @returns {Boolean}
*/
function isValidAge(date) {
return moment().diff(moment(date), 'years') >= 18;
}

/**
* @param {Object} identity
* @returns {Boolean}
Expand Down Expand Up @@ -97,6 +106,12 @@ function isValidIdentity(identity) {
return false;
}

if (!isValidAge(identity.dob)) {
showBankAccountFormValidationError(translateLocal('bankAccount.error.age'));
showBankAccountErrorModal();
return false;
}

if (!isValidSSNLastFour(identity.ssnLast4)) {
showBankAccountFormValidationError(translateLocal('bankAccount.error.ssnLast4'));
showBankAccountErrorModal();
Expand Down
4 changes: 2 additions & 2 deletions src/pages/ReimbursementAccount/IdentityForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ const IdentityForm = ({
placeholder={translate('common.dateFormat')}
value={dob}
onChangeText={(val) => {
if (error === translateLocal('bankAccount.error.dob')) {
if (error === translateLocal('bankAccount.error.dob') || error === translateLocal('bankAccount.error.age')) {
hideBankAccountErrors();
}
onFieldChange('dob', val);
}}
errorText={error === translateLocal('bankAccount.error.dob') ? error : ''}
errorText={error === translateLocal('bankAccount.error.dob') || error === translateLocal('bankAccount.error.age') ? error : ''}
/>
<ExpensiTextInput
label={`${translate('common.ssnLast4')}`}
Expand Down

0 comments on commit ddd7f92

Please sign in to comment.