Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
How can we unable to entry if first number is 0 in textbox. For example :

If anyone enters :

a) 000000000     - not accept
b) 0000001     - accept
b) 0000001002     - accept
b) 0     - not accept
         
If any one have an idea kindly share to me.
Posted

OnBlur of the Textbox call a javascript function say 'fnCheckInput'.
JavaScript
function fnCheckInput()
{
     //Parse it to intger. If the value contains only 0's in that then it'll become 0.
     var controlValue = document.getElementById('TextBox1').value;
     var s = parseInt(controlValue);
     //If the value is 0
     if(s == 0)
     {
          document.getElementById('TextBox1').value = "";//Set empty text to textbox
          return false;
     }
     return true;
}

Here is your HTML:
ASP.NET
<asp:textbox id="TextBox1" runat="server" onblur="return fnCheckInput();" xmlns:asp="#unknown"></asp:textbox>

And also, you need to ensure that only numbers should be entered in TextBox. Use some validation control for that.


--Amit
 
Share this answer
 
Comments
__TR__ 4-Jan-13 1:33am    
My 5!
_Amy 4-Jan-13 1:35am    
Thanks Tejas. :)
[no name] 4-Jan-13 4:04am    
My 4.99 ;). best solution for asp.net. But cant we do anything which will be as good for win applications... :) just a thought
_Amy 4-Jan-13 4:14am    
Thanks for your 4.99. :)
Anyway good thought. ;)
try this

C#
if(Convert.ToDouble(TextBox1.Text)==0)
{
//validation
}

Thanks
 
Share this answer
 
I have solved this. Its a minor task !

C#
int idd = Convert.ToInt16(hour_value.text);
          int p = 0;
   if (idd > p)
   {

   }
   else
   {

   }
 
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