D
D
DTX2016-04-07 22:07:07
JavaScript
DTX, 2016-04-07 22:07:07

How to allow input of certain characters?

Tried onKeyUp with code like this:

event.target.value = event.target.value.replace(/[^-A-Za-zА-Яа-я]/gi, "");

But it works a little wrong

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DTX, 2016-04-07
@DirecTwiX

onKey(event: KeyboardEvent) {
    console.log(event);
    //189 - тире
    if (event.keyCode != 189 && !String.fromCharCode(event.keyCode).replace(/[^0-9A-Za-zА-Яа-я]/gi, "")) return false;
    
    //(<HTMLInputElement>event.target).value = (<HTMLInputElement>event.target).value.replace(/[^-A-Za-zА-Яа-я]/gi, "");
  }

A
Alexey Ukolov, 2016-04-07
@alexey-m-ukolov

But it works a little wrong
When the code for checking certain characters is a little wrong , it needs to be fixed a little in a certain way .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question