Skip to content

Commit ee6ab3e

Browse files
authored
Merge pull request DSpace#1984 from tdonohue/fix_1983
Fix email validation regex to use email validation regex from HTML5 specs
2 parents 2327901 + 1215a7e commit ee6ab3e

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/app/register-email-form/register-email-form.component.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ describe('RegisterEmailComponent', () => {
9595
comp.form.patchValue({email: 'valid@email.org'});
9696
expect(comp.form.invalid).toBeFalse();
9797
});
98+
it('should be valid when uppercase letters are used', () => {
99+
comp.form.patchValue({email: 'VALID@email.org'});
100+
expect(comp.form.invalid).toBeFalse();
101+
});
98102
});
99103
describe('register', () => {
100104
it('should send a registration to the service and on success display a message and return to home', () => {

src/app/register-email-form/register-email-form.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ export class RegisterEmailFormComponent implements OnInit {
7979
this.form = this.formBuilder.group({
8080
email: new FormControl('', {
8181
validators: [Validators.required,
82-
Validators.pattern('^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$')
82+
// Regex pattern borrowed from HTML5 specs for a valid email address:
83+
// https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
84+
Validators.pattern('^[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])?)*$')
8385
],
8486
})
8587
});

0 commit comments

Comments
 (0)