0
I have an input in my system where the user must enter code (only numbers), however he can put several codes, and to separate uses semicolon (;).
To make it work I created the input as text and put a function, which is called via Event (input), which performs the following action:
Input:
<input [disabled]="!selectHierarchy" id="numero" name="pesquisa" type="text" (input)="validaNumber()">
Function:
validaNumber(){
let input = <HTMLInputElement>document.querySelector("#numero");
input.value = input.value.replace(/[^0-9\;]/, '');
}
It worked, when I type it only appears number and semicolon.
But if I copy a text, and paste it into the input, normal text appears. How to make this validation work also when the user pastes a text?
Already tried to use the event
ngChange
? because the validation will only occur when there are changes in the input value– gleisin-dev