multipleOf
Validate that a numeric value is an exact multiple of a given divisor (value % n === 0).
Signature
NguardValidators.Number.multipleOf(n: number): ValidatorFn
| Parameter | Type | Description |
|---|---|---|
n | number | The divisor |
Reactive forms
import { FormControl } from '@angular/forms';
import { NguardValidators } from 'ng-nguard';
// Multiples of 5 — accepts 0, 5, 10, -5, etc.
const step = new FormControl('', [NguardValidators.Number.multipleOf(5)]);
// Multiples of 0.5 — accepts 0, 0.5, 1, 1.5, ...
const halves = new FormControl('', [NguardValidators.Number.multipleOf(0.5)]);
Template-driven forms
<input ngModel name="step" [nguardMultipleOf]="5" />
Error key
{ multipleOf: true }
Notes
- Zero is a multiple of any non-zero divisor (
0 % n === 0). - Negative multiples pass —
-10is a multiple of5. - Fractional divisors work for clean cases (
0.5,0.25). Floating-point arithmetic may produce surprises for irrational values; rely on this for human-friendly steps, not high-precision math. - Numeric strings work —
'15'passesmultipleOf(5). null,undefined, empty string,NaN,Infinityall fail.