Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Validating a JTextField having a float or double value.

843804Sep 18 2002 — edited Dec 10 2004
Hello,
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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 7 2005
Added on Sep 18 2002
6 comments
874 views