Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In the following code , in textbox16, if I enter 1234567890 (10 digit - mobile number) it fails. If I enter 123456789 (9digits) it works! Can anyone help me out.

C#
protected void TextBox16_TextChanged(object sender, EventArgs e)   // mobile number changing
    {
        int value;
        if (Int32.TryParse(TextBox16.Text, out value) == false)
        {
            // TryParse call fails to convert the value to an integer,
        }
        else
        {
            v_mobile = TextBox16.Text;
        }
    }


Thanks.
Posted
Updated 17-Apr-13 23:42pm
v2
Comments
Nick Fisher (Consultant) 18-Apr-13 6:05am    
This only fails for me if I enter a value of 2147483648 - which exceeds the limit for an Int32. 2147483647 and 1234567890 both work fine.

Please, read this: Int32.MaxValue[^].
Quote:
The value of this constant is 2,147,483,647; that is, hexadecimal 0x7FFFFFFF.


I would suggest to use string, because of different formatting. For example, if you want to make call to Poland, you need to provide a telephone number, like: +48 000000000 - for mobile-phone.

Quote:
Most telephone networks today (exceptions being private intercom and secure phone networks) are interconnected in the international telephone network, where the format of telephone numbers is standardized by ITU-T in the recommendation E.164. This specifies that the entire number should be 15 digits or shorter, and begin with a country prefix. For most countries, this is followed by an area code or city code and the subscriber number, which might consist of the code for a particular telephone exchange. ITU-T recommendation E.123 describes how to represent an international telephone number in writing or print, starting with a plus sign ("+") and the country code. When calling an international number from a fixed line phone, the + must be replaced with the international call prefix chosen by the country the call is being made from. Some mobile phones allow the + to be entered directly.


More: http://en.wikipedia.org/wiki/Telephone_number[^]
http://en.wikipedia.org/wiki/Telephone_numbers_in_Poland[^]
 
Share this answer
 
v2
Comments
Sridhar Patnayak 18-Apr-13 5:58am    
Good 5+
Maciej Los 18-Apr-13 6:05am    
Thank you ;)
Try using a long variable instead and Int64.TryParse
 
Share this answer
 
Comments
Sridhar Patnayak 18-Apr-13 5:51am    
please let us know the reason of it.
Johnny J. 18-Apr-13 5:51am    
Apart from that, I really don't understand why you want to convert a phone number to a number???? It makes no sense. How do you handle + for international numbers and () for area codes? And if the number starts with a zero, it will of course be removed by the parsing...
Sridhar Patnayak 18-Apr-13 5:55am    
Agree with you
Johnny J. 18-Apr-13 5:52am    
Sridhar: See the links in Kenneth Hauglands answer
hi,

the range of Int32 is -2,147,483,648 to 2,147,483,647 so use Int64 or decimal datatype.
 
Share this answer
 
Comments
Sridhar Patnayak 18-Apr-13 5:50am    
So what, he entered within the range 1234567890
Hi,

use int64, you crossed max value of int 4 byte,
Max value for int 32 is
2,147,483,647
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900