我在aspx
页面中使用RegularExpressionValidator
进行FreeTextBox
控制。
<FTB:FreeTextBox id="FTB" runat="server" />
<asp:RegularExpressionValidator ID="rev" runat="server" ControlToValidate="FTB" ErrorMessage="Content cannot be only space character" ValidationExpression="[^s]+"/>
我不想让文本只有空格字符。客户端必须输入一些a,b,c…
字符。
但是RegularExpressionValidator
拒绝文本中的任何空格字符(例如 2 个单词之间)。
此正则表达式.*[^ ].*
仅当字符串包含的字符串包含的不仅仅是空格时,它才会匹配字符串。我在这里测试了它。
希望我有帮助!
我认为您应该使用与空/非空内容匹配的RequiredFieldValidator
。其他验证器只是忽略空内容,因为听起来您在这里点击了此功能。
试试这个:
第一个解决方案:
^((?!s).)*$
喜欢这个:
.... ValidationExpression="^((?!s).)*$" ....
第二种解决方案:
您可以使用标签代替正则表达式验证器控件,然后在按钮中使用以下代码:
Match s = Regex.Match(TextBox1.Text, @"^((?!s).)*$");
if (!s.Success)
{
Label1.Text = "Incorrect input!";
}