开发者

Validating textboxes ASP.NET

I have a textbox which I'm trying to validate.

I've added a RegularExpressionValidator but I need to add something else which says validate the text if it doesn't equal 'Name'

<asp:TextBox ID="tbName" Text="Name" Vali开发者_如何学CdationGroup="FormSubmit" runat="server" />

<asp:RegularExpressionValidator CssClass="errorpopup" Display="Dynamic" ID="regexpPostcode"
        ValidationGroup="FormSubmit" runat="server" ErrorMessage="<strong>Please enter a valid name.</strong>"
        ControlToValidate="tbName" ValidationExpression="^[a-zA-Z' ']$" SetFocusOnError="true" />

At the moment if you leave the textbox with 'Name' in then it validates but I want it to say that it isn't valid.

Any ideas?


You can also set a required field validator with the InitialValue properly set to "Name". Upon postback, this will force the TextBox to have a value other than "Name" as well as meet the regular expression requirement specified.


You could always use a custom validator to do your watermark and regex checks.


In addition to your regex you could also add a RequiredFieldValidator and set its InitialValue property to "Name". That would deal with the watermark.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜