Date and Currency validation in Angular (4)

后端 未结 9 1761
没有蜡笔的小新
没有蜡笔的小新 2021-01-01 20:28

I am new to Angular. I am using angular 4 reactive forms and figured out how to perform custom validations. Following is my implementation for numeric

functi         


        
9条回答
  •  温柔的废话
    2021-01-01 20:40

    If you're using Angular Material, you can use the MatDatepicker integration with Moment.js to validate a custom date format using FormControl as shown here:

    https://material.angular.io/components/datepicker/overview#customizing-the-parse-and-display-formats

    HTML:

    
    

    TS:

    export const MY_FORMATS = {
      parse: {
        dateInput: 'LL',
      },
      display: {
        dateInput: 'LL',
        monthYearLabel: 'MMM YYYY',
        dateA11yLabel: 'LL',
        monthYearA11yLabel: 'MMMM YYYY',
      },
    };
    
    @Component({
      selector: 'datepicker-formats-example',
      templateUrl: 'datepicker-formats-example.html',
      styleUrls: ['datepicker-formats-example.css'],
      providers: [
        {provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE]},
        {provide: MAT_DATE_FORMATS, useValue: MY_FORMATS},
      ],
    })
    export class DatepickerFormatsExample {
      date = new FormControl(moment());
    }
    

提交回复
热议问题