1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

restricting min no of characters in asp.net text box

Discussion in 'C#' started by DmitryS, Mar 2, 2011.

  1. #1
    how do we restrict min no of characters in asp.net text box control?
    SEMrush
     
    DmitryS, Mar 2, 2011 IP
    SEMrush
  2. sahaya.emate

    sahaya.emate Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You could use "Maxlength" property by assigning the required length you need.
     
    sahaya.emate, Mar 2, 2011 IP
  3. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #3
    That would set the maximum length. For minimum length you would be best off using javascript validation and then backing it up on the server side. There is no actual property within asp.net to set the Minimum Length, although mentioned above there is for 'MaxLength' (but take note that this will not work on Multi-Line textboxes (TextAreas), although the property still exists).
     
    camjohnson95, Mar 3, 2011 IP
  4. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,681
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Use a regular expression to do it like.....

    <asp:RegularExpressionValidator ID="valPassword" runat="server" 
       ControlToValidate="txtPassword"
       ErrorMessage="Minimum password length is 5"
       ValidationExpression=".{5}.*" />
    Code (markup):
     
    AstarothSolutions, Mar 3, 2011 IP