Angular 2 custom validator with parameters

Here is a sample. It’s a min value validator where you pass in a number to validate.

import {Control} from 'angular2/common';

export const minValueValidator = (min:number) => {
  return (control:Control) => {
    var num = +control.value;
    if(isNaN(num) || num < min){
      return {
         minValue: {valid: false}
      };
    }
    return null;
  };
};

More details can be found in the Custom Validators official documentation page.

Leave a Comment

techhipbettruvabetnorabahisbahis forumu