[SOLVED] How to count input value length in typescript(Angular)?


I want to count form control value in reactive form..

          <div class="col-md-3">
            <input type="text" class="form-control" formControlName="PreMobile" (keypress)="keyPress($event)" (focusout)="validation()"/>

This is my Form Control Name.

Form Name is memberApplicationForm

Form Initialization

private initializeForm() {
    this.memberApplicationForm = new FormGroup({
      PreMobile: new FormControl(''),

Now I want to count PreMobile formcontrol input value length.

    // What should be here

How can I do that?


This should do the work:

validation() {

On the form object we can access its controls with their respective values. Try logging this like above and use it as you intended.

Answered By – Chaka15

Answer Checked By – David Goodson (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *