java - How to filter a backspace keyboard input -
i have code gives message when key number pressed:
txtvalueofclause.addeventfilter(keyevent.key_typed, new eventhandler<keyevent>() { @override public void handle(keyevent t) { char ar[] = t.getcharacter().tochararray(); char ch = ar[t.getcharacter().tochararray().length - 1]; if (!(ch >= '0' && ch <= '9')) { system.out.println("the char entered not number"); t.consume(); } } });
now if press on wrong button , press backspace remove it, error message. how can add backspace input if statement?
i have found answer:
txtvalueofclause.addeventfilter(keyevent.key_typed, new eventhandler<keyevent>() { @override public void handle(keyevent t) { char ar[] = t.getcharacter().tochararray(); char ch = ar[t.getcharacter().tochararray().length - 1]; int codebackspace = ch; if (!(ch >= '0' && ch <= '9') && codebackspace!=8) { system.out.println("the char entered not number"); t.consume(); } } });
Comments
Post a Comment