Click here to Skip to main content
15,886,570 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
How do check multiple space in textbox?

exp:
C#
if(textbox1.text == " '(more space)'") // Here is not working
{
  MessageBox.Show("empty");
}

if(textbox1.text == " ")Here is working
{
  MessageBox.Show("empty");
}

Thanks,
Karthikeyan
Bangalore.
Posted
Updated 3-Sep-12 20:52pm
v2

C#
if(textbox1.Text.Trim().Length==0)
MessageBox.Show("empty");
 
Share this answer
 
v2
Comments
pkarthionline 4-Sep-12 3:26am    
Thanks.
Maybe you should use something like:
C#
if (String.IsNullOrWhiteSpace(textBox1.Text))
            MessageBox.Show("empty");

See here for an explanation:
http://msdn.microsoft.com/en-us/library/system.string.isnullorwhitespace[^]
 
Share this answer
 
v2
Comments
pkarthionline 4-Sep-12 3:00am    
But,
String.IsNullOrWhiteSpace is not show.

only show this one

if (String.IsNullOrEmpty(txtFieldName.Text))
MessageBox.Show("empty");

how i check more whitespace ?
JF2015 4-Sep-12 3:07am    
The IsNullOrWhiteSpace may only be available for .NET 4
Timberbird 4-Sep-12 3:06am    
I would only add that this check will give "empty" message even if textbox is actually empty (has no text at all, even spaces), which may be implied, but not technically requested by TS. Checking text length as well would fix it (if needed)

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