Guys

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

Recommended Answers

All 7 Replies

Use something like

if(exampeString.contains("-"))	{
	// etc
}

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

JavaAddict

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"

Oops!!!!!!

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?

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.