Skip to content
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

Added validation for age in Bank Requestor Form #5149

Merged
merged 1 commit into from
Sep 9, 2021
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
1 change: 1 addition & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,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 @@ -396,6 +396,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);
}

/**
*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nab, unnecessary new line here

* @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