Skip to content

Commit

Permalink
validation messages fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
idrayv committed May 4, 2017
1 parent dff0108 commit cbbe335
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions WatchWord/app/auth/register/register-form.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,45 @@ export class RegisterFormControl extends FormControl {

getValidationMessages() {
let messages: string[] = [];

if (this.errors) {
for (let errorName in this.errors) {
switch (errorName) {
case "required":
messages.push(`${this.label} must be filled in!`);
break;
case "minlength":
messages.push(`A ${this.label} must be at least ${this.errors['minlength'].requiredLength} characters!`);
messages.push(`${this.label} must be at least ${this.errors['minlength'].requiredLength} characters!`);
break;
case "maxlength":
messages.push(`A ${this.label} must be less than ${this.errors['maxlength'].requiredLength} characters!`);
messages.push(`${this.label} must be less than ${this.errors['maxlength'].requiredLength} characters!`);
break;
case "pattern":
messages.push(`The ${this.label} is invalid!`);
messages.push(`${this.label} is invalid!`);
break;
}
}
}

return messages;
}
}

export class RegisterFormGroup extends FormGroup {
constructor() {
super({
login: new RegisterFormControl("Login", "login", "", Validators.compose(
[
Validators.required,
Validators.maxLength(20)
]
)),
password: new RegisterFormControl("Password", "password", "", Validators.compose(
[
Validators.required,
Validators.minLength(4)
]
)),
email: new RegisterFormControl("Email", "email", "", Validators.compose(
[
Validators.required,
Validators.pattern(/^(([^<>()\[\]\\.,;:\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,}))$/)
]
))
login: new RegisterFormControl("Login", "login", "", Validators.compose([
Validators.required,
Validators.maxLength(20)
])),
password: new RegisterFormControl("Password", "password", "", Validators.compose([
Validators.required,
Validators.minLength(4)
])),
email: new RegisterFormControl("Email", "email", "", Validators.compose([
Validators.required,
Validators.pattern(/^(([^<>()\[\]\\.,;:\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,}))$/)
]))
})
}

Expand Down

0 comments on commit cbbe335

Please sign in to comment.