Register  |  Login




Stereo9

Question

Status: Open Points: 125 Time: 06:52 - Feb 08, 2010  

araviin92

How do validate a JtextField which will ensure that the maximum numbers typed should only be 8?

Pls help by adding in codes into the codes that i have given below. I need to add in codes to restrict users of a maximum of 8 numbers and no text shld be entered.

if(jTextFieldHpNo.getText().trim().equals(""))
JOptionPane.showMessageDialog(myFrame, "Please enter your Handphone no.");

Categories

Answer Discussion
Tutorials

 

Q&A System for Websites and Corporate Collaboration

Advertisement

  • Generates significant organic traffic for websites
  • Saves companies money, resources, and time

kalpaprasad7744

Date:: May 02, 2010

Time:: 13:57

i also want to know how to add maximum number of elements foe jtextfield. but i know the code for add only integers for field


String HpNo = jTextFieldHpNo.getText();

try {
int HpNo1=Integer.parseInt(HpNo);
jOtherTextField.requestFocusInWindow();//this is what do you want if adding things are all integers. i put go to other text field
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Data Type is not correct.\n"+"Plese contact System Administrator or recheck the details", "ERROR", JOptionPane.ERROR_MESSAGE);
jTextFieldHpNo.setText("");
jTextFieldHpNo.requestFocusInWindow();
}

in this example if you add things that all are not in int type it give error message and if we select ok then clear that field and cursor is that field



Answer this Question

New User

Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:

Forgot Your Password?

Tutorials cannot be submitted until the Answer Discussion is complete.

Submit answers in the Answer Discussion area

Ask a Question

Have a new question? Ask!

You have 100 characters to use



Top Experts

View More

Rank

Expert

Points

1.

nidhi

9829

2.

oracleofDelphi

6493

3.

rcastagna

5596

4.

LAGM

4773

5.

PeterNZ

3487

6.

Mason

2770

7.

gonzalo

2765

8.

jgivoni

2303

9.

xarcus

1820

10.

Anpanman

917

Become an Expert

Register today to share your knowledge with the community and be recognized and rewarded for your contributions.


Register Here




"Psst, Quomon is a great site. Pass it on."     Tell a Friend  |   Link To Us  |   Save to Delicious  |   Digg! Digg it



Language Options

English:

www.quomon.com

Español:

www.quomon.es