Created
August 26, 2016 11:07
-
-
Save qdouble/1c1e137bf6ec0e7c901a2040bfde8851 to your computer and use it in GitHub Desktop.
Min-max validator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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