问题描述
我有一个文本框,我需要确认,以便用户可以输入输入最多四个字符,它们可以是字母数字。我使用VS2003,.NET 1.1。
请让我知道什么是前pression我应该使用来验证这个条件
任何帮助将是巨大的。谢谢!
试过这样的:
< ASP:文本框的id =wtxtTPP的tabIndex =2=服务器的CssClass =TEXTWIDTH =144pxMAXLENGTH =4/>
< ASP:RegularEx pressionValidator ID =RegularEx pressionValidator1的风格=的z-index:101;左:208px;位置:绝对的; TOP:16px的=服务器的ErrorMessage =RegularEx pressionValidatorValidationEx pression =^([\\ S \\ S] {0,4})$的ControlToValidate =wtxtTPP/>
<输入风格=的z-index:102;左:88px;位置:绝对的;顶部:72px类型=提交值=提交ID =Submit1NAME =Submit1=服务器&GT ;
正如你所说,使用常规的前pression验证和前pression设置是这样的:
^([\\ S \\ S] {0,4})$
与所需的最大lenght更换4。
更新:
< ASP:文本框的id =wtxtTPP=服务器/>< ASP:RegularEx pressionValidator ID =RegularEx pressionValidator1=服务器
的ErrorMessage =RegularEx pressionValidator
ValidationEx pression =^([\\ S \\ S] {0,4})$
的ControlToValidate =wtxtTPP/>< ASP:按钮的ID =Button1的=服务器文本=按钮/>
这工作得很好,对我来说。我换成你与正常的asp.net按钮提交按钮,简化了所有不需要的东西的例子。结果
一般情况下,如果你只有一个行文本框,你可以限制与 MAXLENGTH =文本长度4
像你一样。不需要一个验证。
I have an text box i need to validate so that the user can enter enter up to four character and they can be alphanumeric. I am using VS2003, .NET 1.1.
Please let me know what is the expression i should use to validate this conditionany help would be great. Thanks!
Tried like this:
<asp:TextBox id="wtxtTPP" tabIndex="2" runat="server" CssClass="text" Width="144px" MaxLength="4" />
<asp:RegularExpressionValidator id="RegularExpressionValidator1" style="z-index: 101; left: 208px; position: absolute; TOP: 16px" runat="server" ErrorMessage="RegularExpressionValidator" ValidationExpression="^([\S\s]{0,4})$" ControlToValidate="wtxtTPP" />
<input style="z-index: 102; left: 88px; position: absolute; top: 72px" type="submit" value="Submit" id="Submit1" name="Submit1" runat="server">
As you said, use a Regular Expression Validator and set the expression to something like this:
^([\S\s]{0,4})$
Replace the 4 with your desired max lenght.
Update:
<asp:TextBox id="wtxtTPP" Runat="server" />
<asp:RegularExpressionValidator id="RegularExpressionValidator1" runat="server"
ErrorMessage="RegularExpressionValidator"
ValidationExpression="^([\S\s]{0,4})$"
ControlToValidate="wtxtTPP" />
<asp:Button ID="Button1" runat="server" Text="Button" />
This works just fine for me. I replaced your submit button with a normal asp.net button and simplified out all the unneeded stuff for the example.
In general, if you only have a one line textbox, you can just limit the text length with MaxLength="4"
as you did. No need for a Validator.
这篇关于如何使用文本框上RegularEx pressionValidator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!