Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a FreeTextBox FTB in my aspx page.



<asp:ValidationSummary ID="Alert" runat="server" CssClass="failureNotification" HeaderText=""/>

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="FTB" ErrorMessage=" Content cannot be empty"></asp:RequiredFieldValidator>

I've used RequiredFieldValidator before for `TextBox` control.

Now I use it for FreeTextbox control. It works fine if I let the FreeTextBox empty, but I doent show the ErrorMessage when the FreeTextBox is full of space character.

As recommended, I use RegularExpressionValidator

<asp:RegularExpressionValidator ID="rev" runat="server" ControlToValidate="FTB" ErrorMessage="Content cannot be only space character" ValidationExpression="[^\s]+"/>

But the RegularExpressionValidator is deny any space character in the text (space between words).
I just only want to not allow the text which has full of space characters.

Help!!!
Posted
Updated 14-Nov-13 20:35pm
v2
Comments
♥…ЯҠ…♥ 15-Nov-13 2:18am    
words without space is possible? two or more spaces possible between the words?
Vy Clarks 15-Nov-13 2:34am    
I mean: it allow the space between words. But not allow a string include only space character

1 solution

Hi Clarks,

Try this
RegEx:
^\w+( \w+)(\s*)$
Which allows space, I have tested in here http://www.myregextester.com/index.php works fine, you too do the test and confirm it.

Hope this helps you a bit.

Regards,
RK
 
Share this answer
 
v4
Comments
Vy Clarks 15-Nov-13 3:13am    
perfect, it works fine, thank you so much
♥…ЯҠ…♥ 15-Nov-13 3:14am    
Glad...!!!
Vy Clarks 15-Nov-13 6:03am    
oh, but it doesnt allow the string which has last character is space. For example: "abc "
♥…ЯҠ…♥ 15-Nov-13 6:09am    
updated my solution, vote it up if it deserves ;-). At the end it may have any number of spaces is that ok for you?
♥…ЯҠ…♥ 15-Nov-13 6:14am    
what happened? not working?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900