Wednesday, April 20, 2011

ASP.NET validate

I want to validate an asp.net texbox with min char=3, max=10 and no special characters. I do not want to use a plugin of jQuery but plain jQuery

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

How do I about it.

P.S - I asked the question earlier then edited it, but can't find the question now. Seems like it did not get posted.

From stackoverflow
  • In asp.net you can use the validate control. Either a custom validator or a reg ex validator.

    Something like this

    <asp:RegularExpressionValidator ID="RegularExpressionValidatorEmail" runat="server"
            ControlToValidate="TextBox1" ErrorMessage="Error error..."
            ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" Display="Static" ></asp:RegularExpressionValidator>
    
  • Why not use a RegularExpressionValidator with the Regex pattern "[\w]{3, 10}" ?

    Cerebrus : But why, if I may ask? They both are an abstraction of basic Javascript.

0 comments:

Post a Comment