Skip to content

Commit

Permalink
feat: allow multi email in contact field
Browse files Browse the repository at this point in the history
  • Loading branch information
abelkhay committed Mar 25, 2024
1 parent 77cef20 commit 68d1275
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/models/contact/contact.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,26 @@ describe('contact model', (): void => {
telephone: '+687241541'
});
});

it('should allow multi email in courriel field separated by ;', (): void => {
const contactData: ContactToValidate = {
courriel: '[email protected];[email protected]'
};

const contact: Contact = Contact(contactData);

expect(contact).toStrictEqual({
courriel: '[email protected];[email protected]'
});
});

it('should not validate one of multi courriel', (): void => {
const contactData: ContactToValidate = {
courriel: '[email protected];test2@mairie'
};

expect((): void => {
Contact(contactData);
}).toThrow(new CourrielError('[email protected];test2@mairie'));
});
});
2 changes: 1 addition & 1 deletion src/models/contact/contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type Contact = Model<
export type ContactToValidate = Omit<Contact, 'isContact'>;

const COURRIEL_REG_EXP: RegExp =
/^[a-zA-Z0-9_][a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9])+$/u;
/^(?:[a-zA-Z0-9_][a-zA-Z0-9.!#$%&'*+\\=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9])+(?:;|$))+$/u;

const TELEPHONE_REG_EXP: RegExp =
/^(?:(?:\+|00)(?:33|594|262|596|269|687|689|590|508|681)[\s.-]{0,3}(?:\(0\)[\s.-]{0,3})?|0)(?:(?:[1-9](?:[\s.-]?\d{2}){4}|\d{2}(?:[\s.-]\d{3}){2})|\d{6}|\s\d{3}(?:\s\d{2}){3})$/u;
Expand Down

0 comments on commit 68d1275

Please sign in to comment.