Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 76 characters in body
Source Link
AVJT82
  • 73.6k
  • 25
  • 146
  • 170

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); } 

Tested Answer By me:

form.html

<input type="text" (keypress)="restrictNumeric($event)">

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); }

Tested Answer By me:

form.html

<input type="text" (keypress)="restrictNumeric($event)"> 

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); } 
Tested Answer By me: form.html `<input type="text" (keypress)="restrictNumeric($event) >` form.component.ts: restrictNumeric = function (e) { var 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); } 

Tested Answer By me:

form.html

<input type="text" (keypress)="restrictNumeric($event)">

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); }

Tested Answer By me: form.html `<input type="text" (keypress)="restrictNumeric($event) >` form.component.ts: restrictNumeric = function (e) { var 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); } 

Tested Answer By me:

form.html

<input type="text" (keypress)="restrictNumeric($event)">

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); }

Source Link
RohanArihant
  • 2.8k
  • 4
  • 22
  • 30

Tested Answer By me: form.html `<input type="text" (keypress)="restrictNumeric($event) >` form.component.ts: restrictNumeric = function (e) { var 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); }