Kinyanjui Kamau Kinyanjui Kamau - 7 months ago 25
C# Question

Allow a textbox to take zero as first number

I have this telephone number textbox that I want to allow users to be able to enter a zero as the first number as per area code.

e.g. 0720-123-456

enter image description here

In my program, when I click save, The zero gets omitted and gets saved as

enter image description here

in my MySQL database that has an INT field. I have validated the textbox key press event to only allow numbers.

How can I make users be able to save numbers starting with zero?

Answer Source

Solution of your problme is

Change data type of column INT to Varchar


other solution is format you fetched integer value i.e. after fetching phone number from the database format it properly using ToString method and formater But this is not recommended solution