Skip to content

Commit

Permalink
Add validation for register form
Browse files Browse the repository at this point in the history
  • Loading branch information
marvac committed Jan 27, 2019
1 parent 3d46cf5 commit 4f4f726
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions Client/src/app/components/register/register.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnInit, Input, EventEmitter, Output } from '@angular/core';
import { AuthService } from 'src/app/services/auth.service';
import { AlertifyService } from 'src/app/services/alertify.service';
import { FormGroup, FormControl } from '@angular/forms';
import { FormGroup, FormControl, Validators } from '@angular/forms';

@Component({
selector: 'app-register',
Expand All @@ -18,10 +18,10 @@ export class RegisterComponent implements OnInit {

ngOnInit() {
this.registerForm = new FormGroup({
username: new FormControl(),
password: new FormControl(),
confirmPassword: new FormControl();
});
username: new FormControl('', Validators.required),
password: new FormControl('', [Validators.required, Validators.minLength(4), Validators.maxLength(8)]),
confirmPassword: new FormControl('', Validators.required)
}, this.passwordConfirmationValidator);
}

register() {
Expand All @@ -34,6 +34,14 @@ export class RegisterComponent implements OnInit {
console.log(this.registerForm.value);
}

passwordConfirmationValidator(group: FormGroup) {
if (group.get('password').value === group.get('confirmPassword').value) {
return null;
}

return {'mismatch: true'};
}

cancel() {
this.cancelRegister.emit(false);
}
Expand Down

0 comments on commit 4f4f726

Please sign in to comment.