Click here to Skip to main content
15,913,685 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to validate text boxes ?while text boxes are blank of int type then i am getting input type is not in correct format

[Edit]Title updated[/Edit]
Posted
Updated 28-Aug-13 2:03am
v2
Comments
vangapally Naveen Kumar 28-Aug-13 7:35am    
can you explain more........
[no name] 28-Aug-13 7:41am    
yaah! i am trying to store int type data through a text box but if there is no data then it is not taking null because it has int type of data in database and error is input data is not in correct format
[no name] 28-Aug-13 7:47am    
can you explain it briefly
[no name] 28-Aug-13 7:36am    
What you want to validate..??
[no name] 28-Aug-13 7:43am    
i want to validate text boxes. so that if user leave it blank and click submit then it should arises error or message.

demo_reqfieldvalidator[^]

see this...
 
Share this answer
 
Comments
V.Lorz 28-Aug-13 7:52am    
In the example the validator will run in the server and will not validate the format. While redering the page you may inject the jscript code for validating the text editor using one regex.
Does any one remember if client side validators exist for this task?
[no name] 28-Aug-13 9:02am    
in the same way i want that until select the image using dialog box submit process can not be done
C#
          if ( textbox.Text =="" )
          {
              // then assign ur variable null
          }
          else
          {
              // do your coding
          }

it helps pls select as answer
 
Share this answer
 
try this I think this is what you need.............


if (textbox1.Text==""){
messagebox.show("You cannot leave the textbox blank.");
}
else {
//your code here
}



please accept as answer.......

Reagards,
Ahsan Naveed.
 
Share this answer
 
One way:
C#
try
{
    int TheInt = int.Parse( textbox.Text );

    // If it continues format was OK
}
catch
{
    // If exception thrown, format was not Ok,
}


Another:
C#
int TheInt;

if (int.TryParse( textbox.Text, out TheInt ))
{
    // Format was OK
}
else
{
    // Format was not Ok,
}


Yet another: try using regular expressions: Validation with Regular Expressions Made Simple[^]
 
Share this answer
 
v2

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