diff --git a/src/app/access-control/epeople-registry/eperson-form/eperson-form.component.spec.ts b/src/app/access-control/epeople-registry/eperson-form/eperson-form.component.spec.ts index b9aeeb0af26..a2661e461dd 100644 --- a/src/app/access-control/epeople-registry/eperson-form/eperson-form.component.spec.ts +++ b/src/app/access-control/epeople-registry/eperson-form/eperson-form.component.spec.ts @@ -314,7 +314,7 @@ describe('EPersonFormComponent', () => { describe('after inserting email wrong should show pattern validation error', () => { beforeEach(() => { - component.formGroup.controls.email.setValue('test@test'); + component.formGroup.controls.email.patchValue('test@test'); fixture.detectChanges(); }); it('email should not be valid because the email pattern', () => { diff --git a/src/app/access-control/epeople-registry/eperson-form/eperson-form.component.ts b/src/app/access-control/epeople-registry/eperson-form/eperson-form.component.ts index d7d5a0b49c7..a3909495508 100644 --- a/src/app/access-control/epeople-registry/eperson-form/eperson-form.component.ts +++ b/src/app/access-control/epeople-registry/eperson-form/eperson-form.component.ts @@ -40,6 +40,7 @@ import { TYPE_REQUEST_FORGOT } from '../../../register-email-form/register-email import { DSONameService } from '../../../core/breadcrumbs/dso-name.service'; import { ActivatedRoute, Router } from '@angular/router'; import { getEPersonsRoute } from '../../access-control-routing-paths'; +import {VALID_EMAIL_PATTERN} from '../../../core/shared/form-patterns.constants'; @Component({ selector: 'ds-eperson-form', @@ -252,7 +253,7 @@ export class EPersonFormComponent implements OnInit, OnDestroy { name: 'email', validators: { required: null, - pattern: '^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,4}$', + pattern: VALID_EMAIL_PATTERN, }, required: true, errorMessages: { diff --git a/src/app/core/shared/form-patterns.constants.ts b/src/app/core/shared/form-patterns.constants.ts new file mode 100644 index 00000000000..5288120d77b --- /dev/null +++ b/src/app/core/shared/form-patterns.constants.ts @@ -0,0 +1,2 @@ +//Patterns for form validations +export const VALID_EMAIL_PATTERN = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]{0,61})*\.[a-zA-Z]+$/; diff --git a/src/app/info/feedback/feedback-form/feedback-form.component.ts b/src/app/info/feedback/feedback-form/feedback-form.component.ts index 684f974701b..931c5d7c484 100644 --- a/src/app/info/feedback/feedback-form/feedback-form.component.ts +++ b/src/app/info/feedback/feedback-form/feedback-form.component.ts @@ -14,6 +14,7 @@ import { getHomePageRoute } from '../../../app-routing-paths'; import { take } from 'rxjs/operators'; import { NativeWindowRef, NativeWindowService } from '../../../core/services/window.service'; import { URLCombiner } from '../../../core/url-combiner/url-combiner'; +import {VALID_EMAIL_PATTERN} from '../../../core/shared/form-patterns.constants'; @Component({ selector: 'ds-feedback-form', @@ -29,7 +30,7 @@ export class FeedbackFormComponent implements OnInit { * Form builder created used from the feedback from */ feedbackForm = this.fb.group({ - email: ['', [Validators.required, Validators.pattern('^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,4}$')]], + email: ['', [Validators.required, Validators.pattern(VALID_EMAIL_PATTERN)]], message: ['', Validators.required], page: [''], }); diff --git a/src/app/item-page/bitstreams/request-a-copy/bitstream-request-a-copy-page.component.ts b/src/app/item-page/bitstreams/request-a-copy/bitstream-request-a-copy-page.component.ts index 77e1049d87f..e48ea822a04 100644 --- a/src/app/item-page/bitstreams/request-a-copy/bitstream-request-a-copy-page.component.ts +++ b/src/app/item-page/bitstreams/request-a-copy/bitstream-request-a-copy-page.component.ts @@ -20,6 +20,7 @@ import { DSONameService } from '../../../core/breadcrumbs/dso-name.service'; import { Location } from '@angular/common'; import { BitstreamDataService } from '../../../core/data/bitstream-data.service'; import { getItemPageRoute } from '../../item-page-routing-paths'; +import {VALID_EMAIL_PATTERN} from '../../../core/shared/form-patterns.constants'; @Component({ selector: 'ds-bitstream-request-a-copy-page', @@ -64,7 +65,7 @@ export class BitstreamRequestACopyPageComponent implements OnInit, OnDestroy { }), email: new UntypedFormControl('', { validators: [Validators.required, - Validators.pattern('^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$')] + Validators.pattern(VALID_EMAIL_PATTERN)] }), allfiles: new UntypedFormControl(''), message: new UntypedFormControl(''), diff --git a/src/app/register-email-form/register-email-form.component.ts b/src/app/register-email-form/register-email-form.component.ts index df7e9bea5ef..477be0c40de 100644 --- a/src/app/register-email-form/register-email-form.component.ts +++ b/src/app/register-email-form/register-email-form.component.ts @@ -17,6 +17,7 @@ import {AlertType} from '../shared/alert/alert-type'; import {KlaroService} from '../shared/cookies/klaro.service'; import {CookieService} from '../core/services/cookie.service'; import { Subscription } from 'rxjs'; +import {VALID_EMAIL_PATTERN} from '../core/shared/form-patterns.constants'; export const TYPE_REQUEST_FORGOT = 'forgot'; export const TYPE_REQUEST_REGISTER = 'register'; @@ -99,7 +100,7 @@ export class RegisterEmailFormComponent implements OnDestroy, OnInit { Validators.email, // Regex pattern borrowed from HTML5 specs for a valid email address: // https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address - 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])?)*$') + Validators.pattern(VALID_EMAIL_PATTERN) ]; this.form = this.formBuilder.group({ email: new UntypedFormControl('', {