Validating a JTextField having a float or double value.
843804Sep 18 2002 — edited Dec 10 2004Hello,
I need help in validating a JTextfield which will accept a float or double value because it the deposit field and it shouldn't be of length more than 7 before the decimal and 2 after the decimal.That is it should be of length 10.I have written the following code for the validation.
txtDeposit.addKeyListener(new KeyAdapter(){
//Accept only integer value
public void keyTyped(KeyEvent e){
char c = e.getKeyChar();
if((txtDeposit.getText()).length() == 10)
if (!(Character.isDigit(c)))
if(!Character.isISOControl(c))
{
getToolkit().beep();
e.consume();
}
}
});//end of txtDeposit*/
Please help.