Last active
December 24, 2018 00:44
-
-
Save jsmuster/0b6c8912926133c17c059a8647e141e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit } from '@angular/core'; | |
import { FormBuilder, FormGroup, FormControl, Validators } from '@angular/forms'; | |
@Component({ | |
selector: 'input-user-data-form', | |
templateUrl: './input-user-data-form.component.html', | |
styleUrls: ['./input-user-data-form.component.css'] | |
}) | |
export class InputUserDataFormComponent implements OnInit { | |
registered = false; | |
submitted = false; | |
userForm: FormGroup; | |
constructor(private formBuilder: FormBuilder) | |
{ | |
} | |
invalidFirstName() | |
{ | |
return (this.submitted && this.userForm.controls.first_name.errors != null); | |
} | |
invalidLastName() | |
{ | |
return (this.submitted && this.userForm.controls.last_name.errors != null); | |
} | |
invalidEmail() | |
{ | |
return (this.submitted && this.userForm.controls.email.errors != null); | |
} | |
invalidZipcode() | |
{ | |
return (this.submitted && this.userForm.controls.zipcode.errors != null); | |
} | |
invalidPassword() | |
{ | |
return (this.submitted && this.userForm.controls.password.errors != null); | |
} | |
ngOnInit() | |
{ | |
this.userForm = this.formBuilder.group({ | |
first_name: ['', Validators.required], | |
last_name: ['', Validators.required], | |
email: ['', [Validators.required, Validators.email]], | |
zipcode: ['', [Validators.required, Validators.pattern('^[0-9]{5}(?:-[0-9]{4})?$')]], | |
password: ['', [Validators.required, Validators.minLength(5), Validators.pattern('^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])[a-zA-Z0-9]+$')]], | |
}); | |
} | |
onSubmit() | |
{ | |
this.submitted = true; | |
if(this.userForm.invalid == true) | |
{ | |
return; | |
} | |
else | |
{ | |
this.registered = true; | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment