Click here to Skip to main content
15,915,324 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
as i want to validate my textbox. i want that my text box should not be empty at the form submit ion. it must take some value as input but not whitespace.
i have use this:

if(textbox.text=="")
{
errorProvider1.show(textbox,"plese enter your name");


}


this will take white space as input which is not my requirement .

please help me..
Posted
Comments
Tom Marvolo Riddle 7-Feb-14 1:22am    
Try it & let me know

use Trim[^]

C#
if (textbox.Text.Trim() == "")
                {
                    errorProvider1.show(textbox, "plese enter your name");
                }
 
Share this answer
 
Comments
Siva Hyderabad 7-Feb-14 4:11am    
+5
Karthik_Mahalingam 7-Feb-14 4:16am    
Thanks siva:)
Try this:
C#
if (textBox1.Text.Trim()==string.Empty)
  {
 errorProvider1.show(textbox,"plese enter your name");
  }
 
Share this answer
 
Comments
Abhijeet pratap singh 7-Feb-14 1:36am    
what the functionality of Trim
Tom Marvolo Riddle 7-Feb-14 1:37am    
It Removes whitespaces
use String.IsNullOrWhiteSpace(textbox.Text)

C#
if (String.IsNullOrWhiteSpace(textbox.Text))
{
     errorProvider1.show(textbox, "plese enter your name");
}
 
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