Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I use VS2008. In the following code, 'TryParse' works well when I enter upto 9 digits. When I enter 10 digits it is reflecting 'false'.

C#
int value;
           if ( Int32.TryParse(TextBox17.Text, out value) == false)
           {
               v_MyAddressPhoneTag = "";
               Label22.Visible = true;
               RBL7clear();
           }
           else
           {
               v_MyAddressPhoneTag = "*";
               Label22.Visible = false;

           }


XML
<asp:TextBox ID="TextBox17" runat="server"  OnTextChanged="TextBox17_TextChanged"  AutoPostBack="true" MaxLength="10"
   style=" z-index: 1;top: 182px; left: 212px; position: absolute; height: 18px; width: 148px"></asp:TextBox>
Posted

you are most likely hitting the max.value limit for integer values. use a longer integer (Int64 (Long) or if you really need a BigInteger
 
Share this answer
 
You should not treat phone numbers as integer. They are syntactically numbers, but nobody is interested in their numerical value. Use string instead.
Int32's max value[^] is 2,147,483,647. It looks ten digit long but it is not, since it is 32 bit long, thus numbers greater than this value won't fit.

You could use Int64, but you should not.
 
Share this answer
 
v2
Comments
S.Rajendran from Coimbatore 26-Nov-13 5:14am    
Thanks.
Try the sample code given in this link and you will find out the exact problem with your code.
http://msdn.microsoft.com/en-us/library/system.int32.maxvalue(v=vs.110).aspx[^]
 
Share this answer
 
hi if u value is greater than 2147483647, then it will return false..

below properties for Int32

C#
// Summary:
       //     Represents the largest possible value of an System.Int32. This field is constant.
       public const int MaxValue = 2147483647;
       //
       // Summary:
       //     Represents the smallest possible value of System.Int32. This field is constant.
       public const int MinValue = -2147483648;



below properties for Int64

C#
// Summary:
        //     Represents the largest possible value of an Int64. This field is constant.
        public const long MaxValue = 9223372036854775807;
        //
        // Summary:
        //     Represents the smallest possible value of an Int64. This field is constant.
        public const long MinValue = -9223372036854775808;




Choose based on ur requirement..
 
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