Tested Answer By me:
form.htmlform.html
<input type="text" (keypress)="restrictNumeric($event)">
<input type="text" (keypress)="restrictNumeric($event)"> form.component.ts:form.component.ts:
public restrictNumeric(e) { let input; if (e.metaKey || e.ctrlKey) { return true; } if (e.which === 32) { return false; } if (e.which === 0) { return true; } if (e.which < 33) { return true; } input = String.fromCharCode(e.which); return !!/[\d\s]/.test(input); }
public restrictNumeric(e) { let input; if (e.metaKey || e.ctrlKey) { return true; } if (e.which === 32) { return false; } if (e.which === 0) { return true; } if (e.which < 33) { return true; } input = String.fromCharCode(e.which); return !!/[\d\s]/.test(input); }