在文本框验证(无空格) [英] validation on textbox (no space)

查看:141
本文介绍了在文本框验证(无空格)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页中,我有一个文本框,我的要求是我不想在文本框中给予空间,如果用户在给它的文本框指示给在文本框中没有空间的空间。

i have a webpage in that i have a text box, my requirement is i don't want to give space in the textbox if user give space in textbox it give indication no space in the textbox

推荐答案

如果您打算捕捉值,其中空间是不是一个有效的字符,你可以使用<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.regularex$p$pssionvalidator.aspx\">RegularEx$p$pssionValidator:

If you intended to capture a value where spaces aren't a valid character, you could use a RegularExpressionValidator:

<asp:RegularExpressionValidator ID="rev" runat="server" ControlToValidate="txtBox"
    ErrorMessage="Spaces are not allowed!" ValidationExpression="[^\s]+" />
<asp:RequiredFieldValidator ID="rfv" runat="server" ControlToValidate="txtBox" 
    ErrorMessage="Value can't be empty" />

这将prevent的Hello World和数据库,因为它们包含空格,并且将只允许的HelloWorld和数据库作为有效值。因为RegularEx pressionValidator并不prevent必须使用结合一个RequiredFieldValidator用它prevent空白项,关于自己的。

This would prevent "hello world" and "data base" since they contain spaces, and would only allow "helloworld" and "database" as valid values. You must use a RequiredFieldValidator in conjunction with it to prevent blank entries since the RegularExpressionValidator does not prevent that on its own.

指定在的ControlToValidate 属性中的文本框的名称。

Specify the name of the textbox in the ControlToValidate property.

这篇关于在文本框验证(无空格)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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