How can I validate an input of type=\"number\"
to only be valid if the value is numeric or null using only Reactive Forms (no directives)?
Only numbers
The easiest way would be to use a library like this one and specifically you want noStrings
to be true
export class CustomValidator{ // Number only validation
static numeric(control: AbstractControl) {
let val = control.value;
const hasError = validate({val: val}, {val: {numericality: {noStrings: true}}});
if (hasError) return null;
return val;
}
}