I was currently working on my android project when I came across this issue
I want this to convert a String like “0345303709”7 into an integer, but I keep getting a NumberFormatException.
I’ve searched all the questions here, but have not found a solution to my problem.
Below is my Android code:
String edit_cell=cellnumber.getText().toString();
try
{
if(cellnumber.getText().length()==11 && TextUtils.isEmpty(edit_cell)!=true && edit_cell!=null)
{
cell=Integer.valueOf("03462651882");
}
else
{
Toast.makeText(this, "Invalid CellNumber\n Write CellNumber like this Format:\nNetworkCode Followed by your Number\n",Toast.LENGTH_LONG).show();
Toast.makeText(this, "eg:03213213214",Toast.LENGTH_LONG).show();
}
}
catch(Exception ex)
{
Toast.makeText(this, "Invalid cellnumber\n Write cellNumber line this format:\n Network code followed by your number\n",Toast.LENGTH_LONG).show();
Toast.makeText(this, "eg:03213213214",Toast.LENGTH_LONG).show();
}
I am using eclipse Helios IDE and android version is 2.2 api 8
It’s too big for an Integer, you need a Long.
Edit
Didn’t notice that it was a phone number – definitely store it as a String.
As for validation, a lot of people have dealt with that problem before. See here, for example: A comprehensive regex for phone number validation