(max: number)
| 484 | * See `Validators.max` for additional information. |
| 485 | */ |
| 486 | export function maxValidator(max: number): ValidatorFn { |
| 487 | return (control: AbstractControl): ValidationErrors | null => { |
| 488 | if (control.value == null || max == null) { |
| 489 | return null; // don't validate empty values to allow optional controls |
| 490 | } |
| 491 | const value = parseFloat(control.value); |
| 492 | // Controls with NaN values after parsing should be treated as not having a |
| 493 | // maximum, per the HTML forms spec: https://www.w3.org/TR/html5/forms.html#attr-input-max |
| 494 | return !isNaN(value) && value > max ? {'max': {'max': max, 'actual': control.value}} : null; |
| 495 | }; |
| 496 | } |
| 497 | |
| 498 | /** |
| 499 | * Validator that requires the control have a non-empty value. |
no outgoing calls
no test coverage detected
searching dependent graphs…