From ad4a8a1cca1049f600ebcdce9260c1021cd821a5 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sat, 18 Feb 2017 09:29:59 +0100 Subject: Add email to users --- .../src/app/shared/forms/form-validators/email.validator.ts | 13 +++++++++++++ .../src/app/shared/forms/form-validators/host.validator.ts | 2 +- client/src/app/shared/forms/form-validators/index.ts | 1 + client/src/app/shared/forms/form-validators/user.ts | 9 +++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 client/src/app/shared/forms/form-validators/email.validator.ts (limited to 'client/src/app/shared') diff --git a/client/src/app/shared/forms/form-validators/email.validator.ts b/client/src/app/shared/forms/form-validators/email.validator.ts new file mode 100644 index 000000000..6a2c3bdca --- /dev/null +++ b/client/src/app/shared/forms/form-validators/email.validator.ts @@ -0,0 +1,13 @@ +import { FormControl } from '@angular/forms'; + +export function validateEmail(c: FormControl) { + // Thanks to http://emailregex.com/ + /* tslint:disable */ + const EMAIL_REGEXP = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; + + return EMAIL_REGEXP.test(c.value) ? null : { + email: { + valid: false + } + }; +} diff --git a/client/src/app/shared/forms/form-validators/host.validator.ts b/client/src/app/shared/forms/form-validators/host.validator.ts index ea3e43cb1..ec417e079 100644 --- a/client/src/app/shared/forms/form-validators/host.validator.ts +++ b/client/src/app/shared/forms/form-validators/host.validator.ts @@ -2,7 +2,7 @@ import { FormControl } from '@angular/forms'; export function validateHost(c: FormControl) { // Thanks to http://stackoverflow.com/a/106223 - let HOST_REGEXP = new RegExp( + const HOST_REGEXP = new RegExp( '^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$' ); diff --git a/client/src/app/shared/forms/form-validators/index.ts b/client/src/app/shared/forms/form-validators/index.ts index ab7c2df31..669411a54 100644 --- a/client/src/app/shared/forms/form-validators/index.ts +++ b/client/src/app/shared/forms/form-validators/index.ts @@ -1,3 +1,4 @@ +export * from './email.validator'; export * from './host.validator'; export * from './user'; export * from './video-abuse'; diff --git a/client/src/app/shared/forms/form-validators/user.ts b/client/src/app/shared/forms/form-validators/user.ts index 5b11ff265..0ad0e2a4b 100644 --- a/client/src/app/shared/forms/form-validators/user.ts +++ b/client/src/app/shared/forms/form-validators/user.ts @@ -1,5 +1,7 @@ import { Validators } from '@angular/forms'; +import { validateEmail } from './email.validator'; + export const USER_USERNAME = { VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(20) ], MESSAGES: { @@ -8,6 +10,13 @@ export const USER_USERNAME = { 'maxlength': 'Username cannot be more than 20 characters long.' } }; +export const USER_EMAIL = { + VALIDATORS: [ Validators.required, validateEmail ], + MESSAGES: { + 'required': 'Email is required.', + 'email': 'Email must be valid.', + } +}; export const USER_PASSWORD = { VALIDATORS: [ Validators.required, Validators.minLength(6) ], MESSAGES: { -- cgit v1.2.3