-1

if i give input 21121997 it should convert into 21/12/1997 in date text box. if i give 01012012 then it should convert into 01/01/2012. thats is dd/mm/yyyy format. how to do it? html code-->

      <div class="p-col-12 p-mb-2 p-lg-6 p-mb-lg-0 w-100">
          <mat-form-field appearance="outline" fxFlex="100">
              <mat-label>First Name</mat-label>
                  <input matInput formControlName="firstname" name="firstname" id="firstname">
                                       
          </mat-form-field>
       </div>

       <div class="p-col-12 p-mb-2 p-lg-6 p-mb-lg-0 w-100">
            <mat-form-field appearance="outline" fxFlex="100">
                <mat-label>Date Of Birth</mat-label>
                    <input matInput formControlName="date" [matDatepicker]="picker2" >
                        <mat-datepicker-toggle matSuffix [for]="picker2"></mat-datepicker-toggle>
                        <mat-datepicker #picker2 color="primary"></mat-datepicker>
                                       
              </mat-form-field>
        </div>

ts code-->

 individualCustForm = this.fb.group({
    firstname: [undefined, [Validators.required, Validators.pattern('[a-zA-Z]*')]],
    date: [undefined, [Validators.required]]
  })

1 Answers1

0

You can implement it via moment.js

moment('21121997', 'DMYYYY').format('D/M/YYYY')

The second argument can be made dynamic as per your need.