diff options
Diffstat (limited to 'client/src/app/shared/forms/form-validators')
4 files changed, 24 insertions, 1 deletions
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 @@ | |||
1 | import { FormControl } from '@angular/forms'; | ||
2 | |||
3 | export function validateEmail(c: FormControl) { | ||
4 | // Thanks to http://emailregex.com/ | ||
5 | /* tslint:disable */ | ||
6 | 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,}))$/; | ||
7 | |||
8 | return EMAIL_REGEXP.test(c.value) ? null : { | ||
9 | email: { | ||
10 | valid: false | ||
11 | } | ||
12 | }; | ||
13 | } | ||
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'; | |||
2 | 2 | ||
3 | export function validateHost(c: FormControl) { | 3 | export function validateHost(c: FormControl) { |
4 | // Thanks to http://stackoverflow.com/a/106223 | 4 | // Thanks to http://stackoverflow.com/a/106223 |
5 | let HOST_REGEXP = new RegExp( | 5 | const HOST_REGEXP = new RegExp( |
6 | '^(([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])$' | 6 | '^(([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])$' |
7 | ); | 7 | ); |
8 | 8 | ||
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 @@ | |||
1 | export * from './email.validator'; | ||
1 | export * from './host.validator'; | 2 | export * from './host.validator'; |
2 | export * from './user'; | 3 | export * from './user'; |
3 | export * from './video-abuse'; | 4 | 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 @@ | |||
1 | import { Validators } from '@angular/forms'; | 1 | import { Validators } from '@angular/forms'; |
2 | 2 | ||
3 | import { validateEmail } from './email.validator'; | ||
4 | |||
3 | export const USER_USERNAME = { | 5 | export const USER_USERNAME = { |
4 | VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(20) ], | 6 | VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(20) ], |
5 | MESSAGES: { | 7 | MESSAGES: { |
@@ -8,6 +10,13 @@ export const USER_USERNAME = { | |||
8 | 'maxlength': 'Username cannot be more than 20 characters long.' | 10 | 'maxlength': 'Username cannot be more than 20 characters long.' |
9 | } | 11 | } |
10 | }; | 12 | }; |
13 | export const USER_EMAIL = { | ||
14 | VALIDATORS: [ Validators.required, validateEmail ], | ||
15 | MESSAGES: { | ||
16 | 'required': 'Email is required.', | ||
17 | 'email': 'Email must be valid.', | ||
18 | } | ||
19 | }; | ||
11 | export const USER_PASSWORD = { | 20 | export const USER_PASSWORD = { |
12 | VALIDATORS: [ Validators.required, Validators.minLength(6) ], | 21 | VALIDATORS: [ Validators.required, Validators.minLength(6) ], |
13 | MESSAGES: { | 22 | MESSAGES: { |