Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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()"/>
          </div>

This is my Form Control Name.

Form Name is memberApplicationForm

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Form Initialization

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

Now I want to count PreMobile formcontrol input value length.

  validation(){
    // What should be here
  }

How can I do that?

>Solution :

This should do the work:

validation() {
   console.log(this.memberApplicationForm.controls.PreMobile.value.length);
}

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading