Skip to content

Commit

Permalink
Add support for accents and diacritic marks in email names (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjbp authored Apr 26, 2024
1 parent b12c22e commit 5f19584
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 29 additions & 0 deletions packages/validate/__tests__/integration/validator/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,33 @@ describe('Validate > Integration > validator > email', () => {
expect(await validate(group, group.validators[0])).toEqual(true);
});

it('should return the validityState true for emails names containing accents and diacritic marks', async () => {
expect.assertions(1);
document.body.innerHTML = `<input
id="group1"
name="group1"
data-val="true"
data-val-email="Email error message"
value="Žöé.Štévè@example.com"
type="email">`;
const input = document.querySelector('#group1');
const group = assembleValidationGroup({}, input).group1;
expect(await validate(group, group.validators[0])).toEqual(true);
});

it('should return the validityState false for emails containing accents and diacritic marks in the domain name', async () => {
expect.assertions(1);
document.body.innerHTML = `<input
id="group1"
name="group1"
data-val="true"
data-val-email="Email error message"
value="test@exämple.com"
type="email">`;
const input = document.querySelector('#group1');
const group = assembleValidationGroup({}, input).group1;
expect(await validate(group, group.validators[0])).toEqual(false);
});


});
2 changes: 1 addition & 1 deletion packages/validate/src/lib/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const ACTIONS = {
};

//https://html.spec.whatwg.org/multipage/forms.html#valid-e-mail-address
export const EMAIL_REGEX = /^[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])?)*$/;
export const EMAIL_REGEX = /^[A-Za-zŽžÀ-ÿŠ0-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])?)*$/;

//https://mathiasbynens.be/demo/url-regex
export const URL_REGEX = /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/i;
Expand Down

0 comments on commit 5f19584

Please sign in to comment.