Last active
August 4, 2016 19:49
-
-
Save lancevo/bedaec7c7dfbecd9cb37544e85038553 to your computer and use it in GitHub Desktop.
A validator to validator range of number
This file contains hidden or 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, ValidatorFn} from '@angular/forms'; | |
| export function validateNumberRange(min: number, max:number): ValidatorFn { | |
| return (control: AbstractControl): { [key:string]: any } => { | |
| var value = parseInt(control.value,10); | |
| return (isNaN(value) || (value < min) || (value > max)) ? | |
| {'numberRange' : {'min': min, 'max':max, 'actualValue': value}} : | |
| null | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment