如何不允许FreeTextBox内容充满空格字符? [英] How do not allow FreeTextBox content with full of space characters?

查看:75
本文介绍了如何不允许FreeTextBox内容充满空格字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的aspx页面中有一个FreeTextBox FTB。







< asp:ValidationSummary ID = QUOT;警报" RUNAT = QUOT;服务器"的CssClass = QUOT; failureNotification" HeaderText ="" />



< asp:RequiredFieldValidator ID =" RequiredFieldValidator1" RUNAT = QUOT;服务器"的ControlToValidate = QUOT; FTB"的ErrorMessage = QUOT;内容不能为空">< / asp:RequiredFieldValidator>



我之前使用过RequiredFieldValidator进行`TextBox`控件。



现在我将它用于FreeTextbox控件。如果我让FreeTextBox为空,它可以正常工作,但是当FreeTextBox充满空格字符时我会显示ErrorMessage。



根据建议,我使用RegularExpressionValidator



< asp:RegularExpressionValidator ID =" rev" RUNAT = QUOT;服务器"的ControlToValidate = QUOT; FTB" ErrorMessage ="内容不能只是空格字符 ValidationExpression =" [^ \ _s] +" />



但是RegularExpressionValidator拒绝文本中的任何空格字符(单词之间的空格)。

我只想不允许带有空格字符的文本。



帮助!!!

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!!!

推荐答案

嗨克拉克斯,



试试这个
Hi Clarks,

Try this
RegEx:

^ \w +(\ w +)(\ * *)

^\w+( \w+)(\s*)


哪个允许空格,我在这里测试了 http://www.myregextester.com/index.php 工作正常,你也做了测试并确认了。



希望这会对你有所帮助。



问候,

RK

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


这篇关于如何不允许FreeTextBox内容充满空格字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆