I have been trying to figure this out until this very moment

The problem is I need a piece of code that will not allow the user to enter any negative number in the text box

This how it should work, if the user trries to enter this "-" sign the text box should not do anything, it should remain empty and selected, Please guys Im desperate, any help will be highly appreciated

Thanking you in advance

8 Years
Discussion Span
Last Post by stultuske

Can you do me a faviour and allow me to be honest with you, I dont know what is going on to the above code, the thing is I never did JAVA And few days back I got an internship position to develop JAVA so they asked me to do what they called a simple test, to validate this text box and it should not accept negave ('-') at all so if you could possible do that for me please coz no one is willing to help me here they said I should atleast try and I dont even know where to start, I have tried Google but I came empty handed


If you have never done java then why should you get that position?
And if you are looking for the entire code we are not going to help you. Besides we don't know if it swing or jsp, or if you want to use javascript to do the validation at the client.
All we can tell you is that when the user submits the input,
take it,
put it in String,
convert it into a number,
check if the number is negative or not



this is a learning process of Java or training, there is no way in hell a person can know everything within few weeks all I ever asked was anybody's help on how to code the textbox that should not at all accept a negative number from the user, neither it should show it when the user enters it on the textbox, it should just hang there, selected until the user comes into her senses and realise the meaning of "Enter a positive number"



This is what I was looking for, makes sense now hey,

public void keyTyped(KeyEvent event) {
                if (event.getKeyChar() == KeyEvent.VK_MINUS) AmountTo_Edit.fireEditingStopped();

whether it is possible to validate input in a textfield using core java?

answer is the same as the answer on the question:
is it possible to start a new thread for a new question?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.