Click here to Skip to main content
11,631,534 members (70,438 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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.

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 17-Apr-13 23:41pm
Edited 17-Apr-13 23:42pm
v2
Comments
Nick Fisher (Consultant) at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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[^]
  Permalink  
v2
Comments
Sridhar Patnayak at 18-Apr-13 5:58am
   
Good 5+
Maciej Los at 18-Apr-13 6:05am
   
Thank you ;)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try using a long variable instead and Int64.TryParse
  Permalink  
Comments
Sridhar Patnayak at 18-Apr-13 5:51am
   
please let us know the reason of it.
Johnny J. at 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 at 18-Apr-13 5:55am
   
Agree with you
Johnny J. at 18-Apr-13 5:52am
   
Sridhar: See the links in Kenneth Hauglands answer
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

hi,

the range of Int32 is -2,147,483,648 to 2,147,483,647 so use Int64 or decimal datatype.
  Permalink  
Comments
Sridhar Patnayak at 18-Apr-13 5:50am
   
So what, he entered within the range 1234567890
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Hi,

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

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

  Print Answers RSS


Advertise | Privacy | Mobile
Web01 | 2.8.150723.1 | Last Updated 18 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100