0

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());
3
Contributors
3
Replies
17
Views
4 Years
Discussion Span
Last Post by JamesCherrill
0

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

1

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.

1

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.

This topic has been dead for over six months. 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.