Im trying to input 11 digit numbers but i got an error when parsing from string to int
 JLabel lblMobile = new JLabel("Mobile No. :");  
add(lblMobile);

 JTextField txtMobile = new JTextField("");
add(txtMobile);




  int CUSMobnum = Integer.parseInt(txtMobile.getText());

Recommended Answers

All 3 Replies

it only accept 9 digits.. and i want to insert 11 digit numbers..

you get an error on 11 digits, because an int can not store that big a value. please choose another data type.
in your above code, there is no restriction whatsoever on the field, and saying "I got an error" is of very little use if you don't say what kind of error.
in next posts, please provide some more information. it'll be easier for us to help you out.

There's no reason to use an integer field to store phone numbers. You won'r be doing arithmetic with them.
Most people prefer to enter and see them with some formatting, eg a - or blanks between groups of digits. There is also the convention for international prefixes that looks like "+33 (0)5 53 etc". Those are all very good reasons to hold the original String, and not try to parse it as integer.

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.