I have a form in Angular which i want that the user will only submit a full number (not decimal) and he will not have the option to write .(dot) symbol in the form in order to write the decimal number. I want to block completely the option to write .(dot) at the form. Is it possible?
I tried the solution here : Proper way to restrict text input values (e.g. only numbers) Using regex :
In component.ts add this function
_keyUp(event: any) {
const pattern = /[0-9\+\-\ ]/;
let inputChar = String.fromCharCode(event.charCode);
if (!pattern.test(inputChar)) {
// invalid character, prevent input
event.preventDefault();
}
}
In your template use the following
<input(keyup)="_keyUp($event)">
But it did not work, the option to write .(dot) at the form is still possible.
I want to block completely the option to write .(dot) at the form.