Skip to content

Instantly share code, notes, and snippets.

@qdouble
Created August 26, 2016 11:07
Show Gist options
  • Save qdouble/1c1e137bf6ec0e7c901a2040bfde8851 to your computer and use it in GitHub Desktop.
Save qdouble/1c1e137bf6ec0e7c901a2040bfde8851 to your computer and use it in GitHub Desktop.
Min-max validator
import { AbstractControl } from '@angular/forms';
import { ValidatorFn } from '@angular/forms';
export function minMax(min: number, max: number): ValidatorFn {
return (control: AbstractControl): { [key: string]: any } => {
return control.value < min || control.value > max ?
{ 'invalidNumber': true } :
<any>null;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment