Angular 7 -Reactive Forms Validation

<label class="label-control">Username*</label>
<input type="text" autocomplete="new-password" formControlName="username" class="form-control" (blur)="verifyUsername($" minlength="1" maxlength="20">
<div *ngIf="editAuthenticationform.controls['username'].invalid && (editAuthenticationform.controls['username'].dirty || editAuthenticationform.controls['username'].touched)" class="error formError">
<div *ngIf="editAuthenticationform.controls['username'].errors.required">Username is required.</div></div>
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';

// import custom validator to validate that password and confirm password fields match
import { MustMatch } from './_helpers/must-match.validator';

    selector: 'app',
    templateUrl: 'app.component.html'

export class AppComponent implements OnInit {
    registerForm: FormGroup;
    submitted = false;

    constructor(private formBuilder: FormBuilder) { }

    ngOnInit() {
        this.registerForm ={
            firstName: ['', Validators.required],
            lastName: ['', Validators.required],
            email: ['', [Validators.required,]],
            password: ['', [Validators.required, Validators.minLength(6)]],
            confirmPassword: ['', Validators.required]
        }, {
            validator: MustMatch('password', 'confirmPassword')

    // convenience getter for easy access to form fields
    get f() { return this.registerForm.controls; }

    onSubmit() {
        this.submitted = true;

        // stop here if form is invalid
        if (this.registerForm.invalid) {

        alert('SUCCESS!! :-)\n\n' + JSON.stringify(this.registerForm.value))

2,179 Replies to “Angular 7 -Reactive Forms Validation”

  1. It is with sad regret to inform you that because of the Covid pandemic is shutting down.

    We have lost family members and colleagues and have decided to shut down

    It was a pleasure serving you all these years. We have made all our databases available for $99 (All of it for $99) for those interested.

    Kind Regards,

  2. I don’t even know the way I stopped up here, however I assumed
    this submit was great. I do not recognize who you might be however definitely you’re going
    to a famous blogger when you aren’t already. Cheers!

    Here is my web-site mcse career – Nila,

  3. Paragraph writing is also a fun, if you be acquainted with then you can write or else
    it is complicated to write.

    Also visit my website; cna certification exams, Charles,

  4. Usually I don’t read post on blogs, however I wish to say that this
    write-up very pressured me to take a look at and do so!
    Your writing taste has been surprised me. Thanks, very great post.

    my webpage mblex test – Imogen

  5. My brother recommended I might like this blog.
    He was totally right. This post actually made my day.
    You can not imagine simply how much time I had spent for this
    information! Thanks!

    My blog post; internet marketing tips (Layla)

  6. I visit each day a few sites and information sites to read articles
    or reviews, however this weblog offers quality based writing.

    My webpage – asvab test [Jon]

  7. Oh my goodness! Amazing article dude! Thank you so much,
    However I am having problems with your RSS. I don’t know
    why I cannot join it. Is there anybody getting identical RSS problems?
    Anyone that knows the solution can you kindly respond?

    Here is my homepage: mcitp certification

  8. First of all I would like to say terrific blog! I had a plus certification (Vaughn) quick question which I’d like to
    ask if you don’t mind. I was curious to know
    how you center yourself and clear your head before writing.
    I have had a difficult time clearing my mind in getting
    my thoughts out there. I truly do take pleasure in writing however it just seems like the first 10 to
    15 minutes tend to be wasted simply just trying to figure out how to begin. Any recommendations or hints?
    Thank you!